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

Is there a possibility to save just the key to the DB? #11

Closed
kevman opened this issue Dec 1, 2014 · 9 comments
Closed

Is there a possibility to save just the key to the DB? #11

kevman opened this issue Dec 1, 2014 · 9 comments

Comments

@kevman
Copy link

kevman commented Dec 1, 2014

How can I save just the key without the scheme, bucket name and S3 domain name?

@gsuess gsuess added the question label Dec 1, 2014
@gsuess
Copy link
Contributor

gsuess commented Dec 1, 2014

Currently the only way is to parse it our of the URL.

var parser = document.createElement('a');
parser.href = url;
var key = parser.pathname;

Will look into making this easier in a future release.

@gsuess
Copy link
Contributor

gsuess commented Dec 1, 2014

Is this for a CDN?

@kevman
Copy link
Author

kevman commented Dec 1, 2014

Ok. Thank you!

Is this for a CDN?

In the future I would like to use AWS Lambda to resize images. But to work with AWS Lambda I need 2 buckets and I need to save just the key name without the extra stuff. So I can switch buckets.

@gsuess
Copy link
Contributor

gsuess commented Dec 1, 2014

OK, I will expose an API for accessing that information.

@gsuess
Copy link
Contributor

gsuess commented Dec 1, 2014

Actually there is already a better way than above to obtain the key, albeit cumbersome:

var key = _.findWhere(uploader.instructions.postData, {name: "key"}).value;

@kevman
Copy link
Author

kevman commented Dec 1, 2014

Perfect, I tried the code and it works! But as you said, it's a little bit cumbersome. Thank you!

@gsuess gsuess self-assigned this Dec 4, 2014
@gsuess gsuess closed this as completed in 28241a2 Dec 4, 2014
@kevman
Copy link
Author

kevman commented Dec 5, 2014

How is this working now? Is this correct (I couldn't try it yet)?

var key = uploader.param('key');

@gsuess
Copy link
Contributor

gsuess commented Dec 5, 2014

yes, that's correct.

@ibussieres
Copy link

For some reason I can't get it to work. uploader.instructions is undefined and uploader.param('key') is not returning anything either. What am I missing ?

var uploads = _.map(files, function (file) {
    var uploader = new Slingshot.Upload("uploads");
    uploader.send(file, function (error, downloadUrl) {
      if (error) {
        throw new Meteor.Error(500, error.message);
      }

      var doc = {
        size: file.size,
        url: downloadUrl,
        key: // ??
        type: event.target.fileType.value
      };
    });

    return uploader;
  });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants