JoeDalton
JoeDalton

Reputation: 47

Unable to upload file in Parse Server

I trying to deploy my Angular App frontend and my Parse Server Backend in remote but I'm facing file upload (images) issues.

In local everythings works like expected but in remote I can't upload file like I want.

Normally if an image is upload the frontend code upload the image in the filesystem (that it's ok the image successfully save) and the parse backend code (Cloud code with beforeSave trigger) fetch base image url, add to Buffer, resize it for thumb and save it with another name

But in remote, I got a connection timeout when I try to fetch by image url in Cloud Code.

With the console I see the url of image and I can access it directly from the browser.

This is the part of my code that make this operation:

// image url is available
let fimg = await fetch(image.url());

// at this point - connection timeout
let buffer = Buffer.from(await fimg.arrayBuffer());

const resizedImage = await sharp(buffer)
  .resize({
    width: 200,
    height: 200,
    withoutEnlargement: true,
    fit: 'inside',
  })
  .toBuffer();

const file = new Parse.File('photo.jpg', {
  base64: resizedImage.toString('base64')
});

let savedFile = await file.save();
obj.set('imageThumb', savedFile);

Here is the log of parse server:

error: request to https://myapp.ch/api/files/api/6b53117cab2f9adc973de3ea9fe6b47f_minibougies.png failed, reason: connect ETIMEDOUT myip:443 {"code":141,"stack":"FetchError: request to https://myapp.ch/api/files/api/6b53117cab2f9adc973de3ea9fe6b47f_minibougies.png failed, reason: connect ETIMEDOUT myip:443\n    at ClientRequest.<anonymous> (/root/projectApp/node_modules/mailgun.js/dist/mailgun.node.js:2:64984)\n    at ClientRequest.emit (events.js:400:28)\n    at ClientRequest.emit (domain.js:475:12)\n    at TLSSocket.socketErrorListener (_http_client.js:475:9)\n    at TLSSocket.emit (events.js:400:28)\n    at TLSSocket.emit (domain.js:475:12)\n    at emitErrorNT (internal/streams/destroy.js:106:8)\n    at emitErrorCloseNT (internal/streams/destroy.js:74:3)\n    at processTicksAndRejections (internal/process/task_queues.js:82:21)"}

Console only says: error 400 bad request

Any idea?

Upvotes: 0

Views: 237

Answers (1)

JoeDalton
JoeDalton

Reputation: 47

Find a workaround by changing the fileAdapter from FSFilesAdapter to S3Adapter and manage image directly in DigitalOcean Space.

Maybe the Nginx reverse proxy with SSL / parse server / FSFilesAdapter is not a good mix ?

I can resume my work but I think it’s interesting to know more

Upvotes: 0

Related Questions