-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
44 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,27 @@ | ||
import { Cloudinary } from "@cloudinary/url-gen"; | ||
|
||
export const cld = new Cloudinary({ cloud: { cloudName: "djg4ybxvx" } }); | ||
export const cld = new Cloudinary({ cloud: { cloudName: "dau03r7yn" } }); | ||
|
||
export async function uploadImage(file, onLoading) { | ||
onLoading(true); | ||
const formData = new FormData(); | ||
formData.append("file", file); | ||
formData.append("upload_preset", "c9digoqw"); | ||
|
||
// const response = await fetch( | ||
// `https://api.cloudinary.com/v1_1/djg4ybxvx/image/upload`, | ||
// { | ||
// method: "POST", | ||
// body: formData, | ||
// } | ||
// ); | ||
export async function uploadImage({ file, onLoading }) { | ||
onLoading(true); | ||
const formData = new FormData(); | ||
formData.append("file", file); | ||
formData.append("upload_preset", "cdlo4fjr"); | ||
|
||
// if (response.ok) { | ||
// const data = await response.json(); | ||
// onLoading(false); | ||
// return data.secure_url; | ||
// } else { | ||
// onLoading(false); | ||
// throw new Error("Upload failed"); | ||
// } | ||
try { | ||
const response = await axios.post( | ||
`https://api.cloudinary.com/v1_1/djg4ybxvx/image/upload`, // replace with your cloud_name | ||
formData | ||
); | ||
console.log(response.data); | ||
return response.data.secure_url; | ||
} catch (error) { | ||
console.error(error); | ||
const response = await fetch( | ||
`https://api.cloudinary.com/v1_1/dau03r7yn/image/upload`, | ||
{ | ||
method: "POST", | ||
body: formData, | ||
} | ||
); | ||
|
||
if (response.ok) { | ||
const data = await response.json(); | ||
onLoading(false); | ||
return data.secure_url; | ||
} else { | ||
onLoading(false); | ||
throw new Error("Upload failed"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters