0

http://cloudinary.com/documentation/image_upload_api_reference#upload

I tried the following:

user picks from camera roll:

{
    data: "/9j/4AAQSkZJRgABAQAASABIAAD/4QBYRXhpZg..."
    origURL: "assets-library://asset/asset.JPG?id=ED7AC36B-A150-4C38-BB8C-B6D696F4F2ED&ext=JPG",
    uri: "file:///Users/me/Library/Developer/CoreSimulator/Devices/1BC4A449-46CF-4ADE-A9B5-78906C9C50FB..."
}

then on the server (Node.js), I am trying to use uri from above:

  addUserPhoto(uri) {
    const photo = new Promise((resolve, reject) => {
      const base64URI = new Buffer(uri).toString('base64');
      cloudinary.v2.uploader.upload('data:image/jpeg;base64,'+base64URI, {}, (result) => {
        console.log(result);
        resolve(result);
      });
    });
    return photo;
  }

But I get the error: { message: 'Invalid image file', http_code: 400 }

Am not sure about the correct "file". What am I doing wrong? Which field am I supposed to pick from the camera roll data, and how do I convert it to a compatible "file" for Cloudinary API?

atkayla
  • 8,143
  • 17
  • 72
  • 132

1 Answers1

1

The uri is the local filepath to your image (on the phone), so the server doesn't have access to it.

The way to send an image to a distant host is to send the data.

So it ended up being the data one. Like this:

data:image/jpeg;base64,/9j/4AAQSkZ...

After that, Node Express was giving me Error: request entity too large (so I thought it was still wrong)

Turns out I had to do: app.use(bodyParser.json({ limit: '50mb' })); app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));

atkayla
  • 8,143
  • 17
  • 72
  • 132