Get cloudinary image as file object and upload again with different public_id
I would like to get an uploaded image (public_id:currentPostId) from cloudinary and upload it again with another public_id (postProperties._id). I tried the following code but got error. Can anyone help me?
var currentPostId = this._id;
if ("undefined" === typeof file) {
var photo=new File(["http://res.cloudinary.com/dcyqpeqbh/image/upload/"+currentPostId+".jpg"],currentPostId+".jpg",{type: "image/jpeg"})
console.log(photo)
postProperties._id = Posts.insert(postProperties);
Cloudinary.upload(photo, {public_id: postProperties._id}, function(err, res) {
console.log("Upload Error: " + err);
console.log("Upload Result: " + res);
console.log(err)
});
POST https://api.cloudinary.com/v1_1/dcyqpeqbh/image/upload 400 (Bad Request)
post_edit.js:58 Upload Error: [object Object]
post_edit.js:59 Upload Result: null
Object {error: Object}
error:Object
message:"Invalid image file"
__proto__:Object
__proto__:Object
0
-
Hi Wang,
You can simply pass the URL of the image to the upload request, something like:
var photo="http://res.cloudinary.com/dcyqpeqbh/image/upload/"+currentPostId+".jpg"
...
Cloudinary.upload(photo, {public_id: postProperties._id}, function(err, res) {
...
Please let us know if it works for you?
0
Post is closed for comments.
Comments
1 comment