Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions netlify-plugin-cloudinary/src/lib/cloudinary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,34 +203,38 @@ export async function getCloudinaryUrl(options: CloudinaryOptions) {
}

let results
const maxAttempts = 3;

if (canSignUpload) {
// We need an API Key and Secret to use signed uploading

try {
results = await cloudinary.uploader.upload(fullPath, {
...uploadOptions,
})
} catch (error) {
console.error(`[Cloudinary] ${ERROR_ASSET_UPLOAD}`)
console.error(`[Cloudinary] \tpath: ${fullPath}`)
throw Error(ERROR_ASSET_UPLOAD)
}
} else {
// If we want to avoid signing our uploads, we don't need our API Key and Secret,
// however, we need to provide an uploadPreset
for (let attempt = 0; attempt < maxAttempts; attempt++) {
try {
results = await cloudinary.uploader.unsigned_upload(
fullPath,
uploadPreset,
{
if (canSignUpload) {
// We need an API Key and Secret to use signed uploading
results = await cloudinary.uploader.upload(fullPath, {
...uploadOptions,
},
)
})
break;
}
else {
// If we want to avoid signing our uploads, we don't need our API Key and Secret,
// however, we need to provide an uploadPreset
results = await cloudinary.uploader.unsigned_upload(
fullPath,
uploadPreset,
{
...uploadOptions,
},
)
break;
}
} catch (error) {
console.error(`[Cloudinary] ${ERROR_ASSET_UPLOAD}`)
console.error(`[Cloudinary] path: ${fullPath}`)
throw Error(ERROR_ASSET_UPLOAD)
console.error(`[Cloudinary] Attempt ${attempt + 1} - ${ERROR_ASSET_UPLOAD}`);
console.error(`[Cloudinary] Attempt ${attempt + 1} - \tpath: ${fullPath}`)
if (attempt === maxAttempts - 1) {
// If it's the last attempt, rethrow the error or handle it accordingly
throw Error(ERROR_ASSET_UPLOAD);
} else {
await new Promise(resolve => setTimeout(resolve, 500));
}
}
}

Expand Down