CulturalMe / meteor-slingshot

Upload files directly to AWS S3, Google Cloud Storage and others in meteor
MIT License
595 stars 104 forks source link

Upload fails without error using custom directive #236

Closed Floriferous closed 5 years ago

Floriferous commented 6 years ago

I'm trying to upload a file to a custom object storage service, with the following directive:

import { MAX_FILE_SIZE, BUCKET_PATH } from 'core/api/files/fileConstants';

const API_KEY = 'my-key';
const SECRET_KEY = 'my-secret';

const CustomObjectStorage = {
  directiveMatch: {
    key: Function,
  },

  upload(method, directive, file, meta) {
    const fileKey = directive.key(file, meta);

    return {
      upload: BUCKET_PATH,
      download: `https://${BUCKET_PATH}/${fileKey}`,
      postData: [
        { name: 'accessKey', value: API_KEY },
        { name: 'secret_key', value: SECRET_KEY },
      ],
    };
  },

  maxSize: MAX_FILE_SIZE,
};

Then I start the upload like this:

this.uploader = new Slingshot.Upload(SLINGSHOT_DIRECTIVE_NAME, {
// My metadata..
  });

this.uploader.send(file, (error, downloadUrl) => {
// Error is undefined, yet file does not appear object storage
  if (error) {
   console.log('Error', error);
   this.setState({ error: error.message });
  } else {
   handleSave(file, downloadUrl);
  }
});

Any idea where the issue might lie, or how the error is being swallowed?

Floriferous commented 6 years ago

As you can see in my code above, I didn't add https to my upload URL. Changing it to : https://${BUCKET_PATH} made the upload show proper errors again.