Direct creator uploads api returns same upload id

For Workes & Pages, what is the name of the domain?

What is the issue or error you’re encountering

I’ve been using image api for my web app to upload user’s images. I’m using one-time upload URL but somehow now the api returns same upload URL(same id) every time I request. I’ve changed api key and the id had been changed once, but after that still returns same URL. Heres are my code. export async function getUploadUrl() { const response = await fetch( https://api.cloudflare.com/client/v4/accounts/${process.env.NEXT_PUBLIC_CLOUDFLARE_ACCOUNT_ID}/images/v2/direct_upload, { method: “POST”, headers: { Authorization: Bearer ${process.env.NEXT_PUBLIC_CLOUDFLARE_API_KEY}, }, } ); const data = await response.json(); console.log(data); return data; }

What steps have you taken to resolve the issue?

I’ve changed api key, but still cannot resolve.

Can you share an example of the full request and full response that you’re getting, including headers and body?

Hello, thank you for reply. Here are my requests,

export async function getUploadUrl() {
const response = await fetch(
https://api.cloudflare.com/client/v4/accounts/${process.env.NEXT_PUBLIC_CLOUDFLARE_ACCOUNT_ID}/images/v2/direct_upload,
{
method: “POST”,
headers: {
Authorization: Bearer ${process.env.NEXT_PUBLIC_CLOUDFLARE_API_KEY},
},
}
);
const data = await response.json();// here I only get same result.id
return data;
}
*result
{
result: {
id: ‘some same ID’,
uploadURL: ‘https://upload.imagedelivery.net/{MyID}/{same as id}’
},
success: true,
errors: ,
messages:
}

and uploading image function

for (const [index, preview] of previews.entries()) { //previews has has id and uploadURL and file
  const cloudflareForm = new FormData();
  cloudflareForm.append("file", preview.file);
  const response = await fetch(uploadUrls[index], {
    method: "post",
    body: cloudflareForm,
  });
  if (response.status !== 200) {
    return;
  }
  uploadedImageUrls.push(`https://imagedelivery.net/{MYID}/${preview.id}/public`);
}

*result
POST https://upload.imagedelivery.net/{MYID}/{same id} 409 (Conflict)

it returns error 409 because it’s same uploadURL as url I’ve already uploaded.

I checked direct upload v2, it does return different ids.

I don’t see it in the example, but do you by any chance include id in the request body?

sending same in the request id would produce the same output.

Hello, thank you for reply.

I didn’t put any variables in the request body when I request uploadURL.

But I’ve just tested with Postman and somehow it work perfectly.

what did you test first with? Cloudflare Workers/nodejs/browser?

I’ve tested with node.js. Now I’m trying to chage it to V1.

v1 is deprecated. I suggest to dig what doesn’t work with v2.

This topic was automatically closed after 15 days. New replies are no longer allowed.