aliaksandr-master / gulp-aws-s3-upload

configurable gulp task for uploading to aws-s3 bucket
Other
1 stars 2 forks source link

Triggers error 400 (bad request) or doesn't upload #1

Open Jos512 opened 7 years ago

Jos512 commented 7 years ago

Hi!

Using version 1.1.1, I consistently get the '400' error response when uploading. Looking at the AWS error responses, this happens when "The Content-MD5 you specified did not match what we received.".

For example:

gulp.task('uploadS3', function() {
    return gulp.src('deploy/assets/style.css')
        .pipe(gulpAwsS3Upload({
            onlyNew: false,
            headers: { 
                'Cache-Control': 'max-age=864000, s-maxage=864000, must-revalidate',
                'x-amz-acl': 'public-read'
            },
            aws: {
                key: 'key',
                secret: 'secret,
                bucket: 'bucket',
                region: 'eu-central-1'
            }
        }));
});

Returns:

[10:29:30] Starting 'uploadS3'...
[10:29:30] [FAILED] deploy\assets\style.css -> style.css :: 400
[10:29:30] 'uploadS3' errored after 191 ms
[10:29:30] gulpUploadNewS3Error in plugin 'gulp-upload-new-s3'
Message:
    400
Details:
    domainEmitter: [object Object]
    domain: [object Object]
    domainThrown: false

However, if I set onlyNew to false, then the error message is not generated. But with that case, no file gets uploaded but all 'skipped over':

[10:32:54] Starting 'uploadS3'...
[10:32:54] [SKIPPED] deploy\assets\style.css -> style.css
[10:32:54] Finished 'uploadS3' after 175 ms

So from my uninformed standpoint, there seems to be going something wrong with the MD5 checks.

aliaksandr-master commented 7 years ago

When you see SKIP in the log it means that file has already exists in s3. you need to set onlyNew as false if you want to reupload without checking it. onlyNew provides only shallow checking filename. And you are currently using this flag as false.

const error = (err) => {
  gutil.log(`${chalk.red('[FAILED]')} ${fileMessage} :: ${chalk.red(err.message || err)}`);
};
const upload = () => {
  uploadToS3(file, uploadPath, options, (err) => {
  if (err) {
     error(err);
  } else {
     gutil.log(`${chalk.green('[SUCCESS]')} ${fileMessage}`);
  cache.remember(file);
  }
  taskDone(err, file);
  });
};

As you see when this error is appeared cache shouldn't save it

Anyway. MD5 file checking currently implemented in knox library. this lib using in this package for uploading to S3. And message "The Content-MD5 you specified did not match what we received." could specify to the bug in knox package.

it is really intresting. I tried to reproduce it. but I got no results =(