admin管理员组文章数量:1287647
I wanted to use Cloudinary's API to upload images from the client side for my project.
This is an example from Cloudinary's docs to make signed requests from client side: Link to project.
The project uses Express + Node. I am using Next.js.
A signature is generated and appended to a new FormData through a server function. On the client side, I call this server action to receive the signed form data. Then I append the files(s) and make a request.
I compared the signature generated on the server with the signature received as error. They are the same! The timestamp also matches. I don't know what I am missing now.
I have an old account so it uses "fixed folders" - if that could create any issues.
Here are the server actions:
'use server';
import cloudinary, { cloudinaryConfig } from "./cloudinary.config";
function getUploadSignature(){
// get timestamp in seconds
const timeStamp = Math.round((new Date).getTime() / 1000);
const signature = cloudinary.utils.api_sign_request({
folder: 'imageUploadTest',
timeStamp,
}, cloudinaryConfig.api_secret);
console.log({getSignTS: signature, timeStamp});
return {
cloudName: cloudinaryConfig.cloud_name,
apiKey: cloudinaryConfig.api_key,
timeStamp,
signature,
};
}
export async function getSignedFormData(){
const formData = new FormData();
const { cloudName, apiKey, timeStamp, signature } = getUploadSignature();
formData.append("api_key", apiKey);
formData.append("timestamp", timeStamp);
formData.append("signature", signature);
formData.append("folder", "imageUploadTest");
// remove cloud name before making request;
formData.append('cloudName', cloudName);
return formData;
}
I have also compared the Secret, Key and Cloud name. Everything looks fine and yet I am getting the unauthorized 401.
I wanted to use Cloudinary's API to upload images from the client side for my project.
This is an example from Cloudinary's docs to make signed requests from client side: Link to project.
The project uses Express + Node. I am using Next.js.
A signature is generated and appended to a new FormData through a server function. On the client side, I call this server action to receive the signed form data. Then I append the files(s) and make a request.
I compared the signature generated on the server with the signature received as error. They are the same! The timestamp also matches. I don't know what I am missing now.
I have an old account so it uses "fixed folders" - if that could create any issues.
Here are the server actions:
'use server';
import cloudinary, { cloudinaryConfig } from "./cloudinary.config";
function getUploadSignature(){
// get timestamp in seconds
const timeStamp = Math.round((new Date).getTime() / 1000);
const signature = cloudinary.utils.api_sign_request({
folder: 'imageUploadTest',
timeStamp,
}, cloudinaryConfig.api_secret);
console.log({getSignTS: signature, timeStamp});
return {
cloudName: cloudinaryConfig.cloud_name,
apiKey: cloudinaryConfig.api_key,
timeStamp,
signature,
};
}
export async function getSignedFormData(){
const formData = new FormData();
const { cloudName, apiKey, timeStamp, signature } = getUploadSignature();
formData.append("api_key", apiKey);
formData.append("timestamp", timeStamp);
formData.append("signature", signature);
formData.append("folder", "imageUploadTest");
// remove cloud name before making request;
formData.append('cloudName', cloudName);
return formData;
}
I have also compared the Secret, Key and Cloud name. Everything looks fine and yet I am getting the unauthorized 401.
Share Improve this question asked Feb 23 at 15:15 ManavManav 13 bronze badges1 Answer
Reset to default 0Cloudinary should return a response header that include the error details in the x-cld-error header, and you can see the value by using your browser's web developer tools to examine that response.
版权声明:本文标题:authentication - "Unauthorized" 401 error on making client side upload to Cloudinary - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741313593a2371788.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论