Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thumbnails example -Error: The uploaded data did not match the data from the server. #140

Closed
goodcourage-jimmy opened this issue May 6, 2017 · 4 comments

Comments

@goodcourage-jimmy
Copy link

goodcourage-jimmy commented May 6, 2017

Hello,

I use Thumbnails example, and sometimes (little) I'm getting this error when uploading files from Storage :

Error: The uploaded data did not match the data from the server. As a precaution, the file has been deleted. To be sure the content is the same, you should try uploading the file again.
    at /user_code/node_modules/@google-cloud/storage/src/file.js:1058:21
    at /user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/service-object.js:155:5
    at Object.handleResp (/user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:135:3)
    at /user_code/node_modules/@google-cloud/storage/node_modules/@google-cloud/common/src/util.js:465:12
    at Request.onResponse [as _callback] (/user_code/node_modules/@google-cloud/storage/node_modules/retry-request/index.js:133:7)
    at Request.self.callback (/user_code/node_modules/@google-cloud/storage/node_modules/request/request.js:188:22)
    at emitTwo (events.js:106:13)
    at Request.emit (events.js:191:7)
    at Request.<anonymous> (/user_code/node_modules/@google-cloud/storage/node_modules/request/request.js:1171:10)
    at emitOne (events.js:96:13)

Here is some code snippet, for the deletion part :

index.js

exports.generateThumbnail = functions.storage.object().onChange(event => {
  return thumbnail(event)
})

thumbnail


const gcs = require('@google-cloud/storage')();
const spawn = require('child-process-promise').spawn;

function thumbnail(event) {

    const object = event.data;
    const fileBucket = object.bucket;
    const filePath = object.name;
    const contentType = object.contentType;
    const resourceState = object.resourceState;

    if (!contentType.startsWith('image/')) {
        return;
    }

    const fileName = filePath.split('/').pop();
    if (fileName.startsWith('thumb_')) {
        return;
    }

    if (resourceState === 'not_exists') {
        return;
    }

    const bucket = gcs.bucket(fileBucket);
    const tempFilePath = `/tmp/${fileName}`;
    return bucket.file(filePath).download({
        destination: tempFilePath
    }).then(() => {
        return spawn('convert', [tempFilePath, '-thumbnail', '200x200>', tempFilePath]).then(() => {
            const thumbFilePath = filePath.replace(/(\/)?([^\/]*)$/, `$1thumb_$2`);
            return bucket.upload(tempFilePath, {
                destination: thumbFilePath
            });
        });
    });
}
module.exports = thumbnail;
@nicolasgarnier
Copy link
Contributor

nicolasgarnier commented Oct 5, 2017

It looks like sometimes validation of the uploaded image fails.

It may be failing for good reasons but, if you want you can disable validation by passing validation: false to the bucket.upload call:

return bucket.upload(tempFilePath, {
  destination: thumbFilePath,
  validation: false
});

The alternative is to catch the error and retry the upload. Maybe with something like this:

// Try one upload with validation and if it fails another one without validation.
return bucket.upload(tempFilePath, {
  destination: thumbFilePath
}).catch(e => {
  return bucket.upload(tempFilePath, {
    destination: thumbFilePath,
    validation: false
});

And of course you could do something more sophisticated with multiple retry and exponential backoff etc... :)

If some of you could try this in some cases where these errors usually happen and repport that would be great :)

@PierBover
Copy link

It looks like sometimes validation of the uploaded image fails.

I'm getting this problem too and it seems a very erratic behavior.

Where is the appropriate place to report this bug?

@joelgetaction
Copy link

I'm also seeing this and it's very frustrating! Whenever I update an image I get this issue ...

@nicolasgarnier
Copy link
Contributor

does using validation: false fixes the issue?

Looking at this issue: googleapis/google-cloud-node#2604 it seems that disabling resumable upload could help too.

Can you try passing resumable: false instead of validation: false and see if it works?

Re: the correct place to report this bug would be on https://github.com/googleapis/google-cloud-node/. If resumable uploads are the issue you could add onto googleapis/google-cloud-node#2604

henrik242 added a commit to finn-no/cdn-uploader that referenced this issue Jun 14, 2021
Some uploads randomly return checksum errors. These can be mitigated using
resumable: false (optionally validation: false)

See
- googleapis/google-cloud-node#2604
- firebase/functions-samples#140

Example error:

```$ ../../node_modules/@finn-no/cdn-uploader/index.js --credentials ${CDN_UPLOADER_CREDENTIALS} --project-id foo-storage --bucket-name foo-assets --app-prefix foo-web/_next build/next

/foo/node_modules/@google-cloud/storage/src/file.js:1093
        const error = new Error(message);
                      ^
Error: The uploaded data did not match the data from the server. As a precaution, the file has been deleted. To be sure the content is the same, you should try uploading the file again.
    at /foo/node_modules/@google-cloud/storage/src/file.js:1093:23
    at Object.handleResp (/foo/node_modules/@google-cloud/common/src/util.js:134:3)
    at /foo/node_modules/@google-cloud/common/src/util.js:496:12
    at Request.onResponse [as _callback] (/foo/node_modules/retry-request/index.js:198:7)
    at Request.self.callback (/foo/node_modules/request/request.js:185:22)```
henrik242 added a commit to finn-no/cdn-uploader that referenced this issue Jun 15, 2021
Some uploads randomly return checksum errors. These can be mitigated using
resumable: false (optionally validation: false)

See
- googleapis/google-cloud-node#2604
- firebase/functions-samples#140

Example error:

```$ ../../node_modules/@finn-no/cdn-uploader/index.js --credentials ${CDN_UPLOADER_CREDENTIALS} --project-id foo-storage --bucket-name foo-assets --app-prefix foo-web/_next build/next

/foo/node_modules/@google-cloud/storage/src/file.js:1093
        const error = new Error(message);
                      ^
Error: The uploaded data did not match the data from the server. As a precaution, the file has been deleted. To be sure the content is the same, you should try uploading the file again.
    at /foo/node_modules/@google-cloud/storage/src/file.js:1093:23
    at Object.handleResp (/foo/node_modules/@google-cloud/common/src/util.js:134:3)
    at /foo/node_modules/@google-cloud/common/src/util.js:496:12
    at Request.onResponse [as _callback] (/foo/node_modules/retry-request/index.js:198:7)
    at Request.self.callback (/foo/node_modules/request/request.js:185:22)```
henrik242 added a commit to finn-no/cdn-uploader that referenced this issue Jun 15, 2021
Some uploads randomly return checksum errors. These can be mitigated using
resumable: false (optionally validation: false)

See
- googleapis/google-cloud-node#2604
- firebase/functions-samples#140

Example error:

```$ ../../node_modules/@finn-no/cdn-uploader/index.js --credentials ${CDN_UPLOADER_CREDENTIALS} --project-id foo-storage --bucket-name foo-assets --app-prefix foo-web/_next build/next

/foo/node_modules/@google-cloud/storage/src/file.js:1093
        const error = new Error(message);
                      ^
Error: The uploaded data did not match the data from the server. As a precaution, the file has been deleted. To be sure the content is the same, you should try uploading the file again.
    at /foo/node_modules/@google-cloud/storage/src/file.js:1093:23
    at Object.handleResp (/foo/node_modules/@google-cloud/common/src/util.js:134:3)
    at /foo/node_modules/@google-cloud/common/src/util.js:496:12
    at Request.onResponse [as _callback] (/foo/node_modules/retry-request/index.js:198:7)
    at Request.self.callback (/foo/node_modules/request/request.js:185:22)```
henrik242 added a commit to finn-no/cdn-uploader that referenced this issue Jun 15, 2021
Some uploads randomly return checksum errors. These can be mitigated using
resumable: false (optionally validation: false)

See
- googleapis/google-cloud-node#2604
- firebase/functions-samples#140

Example error:

```$ ../../node_modules/@finn-no/cdn-uploader/index.js --credentials ${CDN_UPLOADER_CREDENTIALS} --project-id foo-storage --bucket-name foo-assets --app-prefix foo-web/_next build/next

/foo/node_modules/@google-cloud/storage/src/file.js:1093
        const error = new Error(message);
                      ^
Error: The uploaded data did not match the data from the server. As a precaution, the file has been deleted. To be sure the content is the same, you should try uploading the file again.
    at /foo/node_modules/@google-cloud/storage/src/file.js:1093:23
    at Object.handleResp (/foo/node_modules/@google-cloud/common/src/util.js:134:3)
    at /foo/node_modules/@google-cloud/common/src/util.js:496:12
    at Request.onResponse [as _callback] (/foo/node_modules/retry-request/index.js:198:7)
    at Request.self.callback (/foo/node_modules/request/request.js:185:22)```
henrik242 added a commit to finn-no/cdn-uploader that referenced this issue Jun 15, 2021
Some uploads randomly return checksum errors. These can be mitigated using
resumable: false (optionally validation: false)

See
- googleapis/google-cloud-node#2604
- firebase/functions-samples#140

Example error:

```$ ../../node_modules/@finn-no/cdn-uploader/index.js --credentials ${CDN_UPLOADER_CREDENTIALS} --project-id foo-storage --bucket-name foo-assets --app-prefix foo-web/_next build/next

/foo/node_modules/@google-cloud/storage/src/file.js:1093
        const error = new Error(message);
                      ^
Error: The uploaded data did not match the data from the server. As a precaution, the file has been deleted. To be sure the content is the same, you should try uploading the file again.
    at /foo/node_modules/@google-cloud/storage/src/file.js:1093:23
    at Object.handleResp (/foo/node_modules/@google-cloud/common/src/util.js:134:3)
    at /foo/node_modules/@google-cloud/common/src/util.js:496:12
    at Request.onResponse [as _callback] (/foo/node_modules/retry-request/index.js:198:7)
    at Request.self.callback (/foo/node_modules/request/request.js:185:22)```
henrik242 added a commit to finn-no/cdn-uploader that referenced this issue Jun 15, 2021
Some uploads randomly return checksum errors. These can be mitigated using
resumable: false (optionally validation: false)

See
- googleapis/google-cloud-node#2604
- firebase/functions-samples#140

Example error:

```$ ../../node_modules/@finn-no/cdn-uploader/index.js --credentials ${CDN_UPLOADER_CREDENTIALS} --project-id foo-storage --bucket-name foo-assets --app-prefix foo-web/_next build/next

/foo/node_modules/@google-cloud/storage/src/file.js:1093
        const error = new Error(message);
                      ^
Error: The uploaded data did not match the data from the server. As a precaution, the file has been deleted. To be sure the content is the same, you should try uploading the file again.
    at /foo/node_modules/@google-cloud/storage/src/file.js:1093:23
    at Object.handleResp (/foo/node_modules/@google-cloud/common/src/util.js:134:3)
    at /foo/node_modules/@google-cloud/common/src/util.js:496:12
    at Request.onResponse [as _callback] (/foo/node_modules/retry-request/index.js:198:7)
    at Request.self.callback (/foo/node_modules/request/request.js:185:22)```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants