File upload on fly fails with 408 error

I have a project uploaded to fly.io which is a node backend that handles uploading of files to cloudinary using express and multer for file uploads.

Here’s the issue: Anytime I try to upload an image greater than 1MB from the api hosted on fly.io, it returns a 408 error with no response message. And it doesnt take long to return that 408 error infact, so it’s not like the image is too large.

When I upload directly from my local server however, it works fine. Even for larger images.

How do I get it fixed please. I’ll really appreciate any help from this wonderful community.
Thanks!

408 is an odd error, I’m not sure our proxy does that as it would usually do 502 and you mentioned it doesn’t take too long to error.

My first suggestion is to look for your logs and try to spot any errors. Then try to check if your uploader library doesn’t have limits for production code.

1 Like

If fly-replay involved? It has a limit of 1MB, but I don’t know what HTTP status code it returns when that occurs.

2 Likes

OK, I can rule out Fly_Replay as the culprit as that results in a message in your log:

[error]cannot retry/replay request because request body has been read past what we're willing to buffer

… and a status code of 502.

But I can confirm that it is possible to write a node application that handles file uploads of greater than 1MB as long a fly replay is not involved.

server.js:

const express = require('express');
const app = express();
app.use(express.static('public'));

const multer  = require('multer');
const upload = multer({ dest: __dirname + '/uploads/' });

app.get('/', function(req, res) {
  res.redirect('/form.html');
});

app.post('/upload', upload.single('image'), function(req, res) {
  if (process.env.FLY_REGION !== process.env.PRIMARY_REGION) {
    console.log('replaying');
    res.set('Fly-Replay', `region=${process.env.PRIMARY_REGION}`)
    res.sendStatus(409);
  } else {
    console.log(req.file);
    res.sendStatus(200);
  }
});

app.listen(3000, () => {
  console.log('Server is listening on port 3000');
});

public/form.html:

<form action="/upload" method="post" enctype="multipart/form-data">
  <input type="file" name="image">
  <input type="submit">
</form>
1 Like

This is what i see when monitoring the api on fly

But it works and uploads perfectly on my local server, and I’m using cloudinary, so it dont think it has any upload limits. On fly however, the image above is what I get, and i see a 408 error status.

And i’m not using fly replay at all.

I really need help on this. Thanks!

Recapping where we are. While our proxy server will return a number of HTTP status codes, 408 doesn’t appear to be one of them. As your app works locally, it is unlikely to be your app.

I’ve posted a small program that you should be able to deploy for yourself as a separate app. If you can deploy that without cloudinary and get it to fail, we will be able to help. If it doesn’t fail for you, that should give you clues where to look next.

1 Like

Alright, I set up the small app like you mentioned, and it didnt return that 408 error.
But cloudinary still works perfectly when working on my local sever.

My (im)possible theory:
Could it be that fly has a timeout for requests made to another 3rd party platforms? I’m thinking that it could be that fly waits for a response from cloudinary, and if it doesn’t get a response within a particular time limit, it closes the connection and throws that error.

Could it be so? Is there anything like that?
Your response is highly appreciated.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.