Question

Upload success with DO space but never show

Posted April 4, 2019 667 views
DigitalOcean Ubuntu 16.04

I’m using DO space for the first time to upload images and documents. I used multer and multer-s3 to upload multiple images. The function works fine and show successful without error. But DO space doesn’t show any updates. The files doesn’t upload to the DO space. I tried URL but no such key.

I set my DO Space:

  • Enable File Listing
  • Enable CDN
  • CORS: allow all the wildcard domain
const bucket = 'MY_DO_UNIQUE_NAME';
const spacesEndpoint = new AWS.Endpoint('sgp1.digitaloceanspaces.com');
const s3 = new AWS.S3({
        endpoint: spacesEndpoint,
        accessKeyId: process.env.DO_ACCESS_KEY,
        secretAccessKey: process.env.DO_SECRET_KEY
 });

const upload = multer({
      storage: multerS3({
        s3:s3,
        bucket: bucket,
        acl: 'public-read',
        key: function (request, file, cb) {
          console.log(file);
          cb(null, file.originalname);
        }
      }),

}).array('file', 100);

upload(req, res, function (error, file, data) {
          if (error) {
            console.log(error);
            return response.redirect("/error");
          }
          console.log('File uploaded successfully.');
});

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

1 answer

Greetings!

I’m sorry about the trouble this is causing for you. My concern is that perhaps your code is not putting out an error, but that this may not be a clear indication that our server has actually accepted the upload. Are you able to fully output the response from our server when you upload the object? Here’s an example of what a successful response might look like to a PUT:

HTTP/1.1 200 OK

Date: Mon, 10 Jul 2017 19:46:06 GMT
x-amz-request-id: tx0000000000000027bd57c-005963d97e-1268c-nyc3a
Content-Length: 0
Accept-Ranges: bytes
Last-Modified: Mon, 10 Jul 2017 19:05:09 GMT
Etag: "fb08934ef619f205f272b0adfd6c018c"
Connection: close

Jarland

Submit an Answer