Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

♻️ Refactor Cloudinary upload logic to add a upload retry #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
colbyfayock merged 6 commits into cloudinary-community:main from taciturnaxolotl:upload-retry
Nov 10, 2023
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
View file Open in desktop
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

AltStyle によって変換されたページ (->オリジナル) /