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

Pass down specific properties to the client callback after the file is uploaded #86

Open
MaazAli opened this issue Mar 30, 2015 · 8 comments

Comments

@MaazAli
Copy link

MaazAli commented Mar 30, 2015

Love the addon, looked at the source and I found it to be even better. I love the interface and the way it's laid out.

I have a few suggestions.

When files are uploaded, the client callback receives two variables error and downloadUrl. Is there a way we can send down a third variable called options which is an object for extra information we may need to update the meteor collection? For example if we want to generate the file name on the server, then we want to update the document with the file name instead of trying to parse the downloadUrl and extract the filename from there.

Either that or make it so that the metaContext that is passed to the server can be passed on every upload. So in this method this.uploader.send(file, metaContext, function(error, downloadUrl) { ... });

@abhishekbatra
Copy link

Hey @MaazAli I was wondering if anyone else would feel the need for this. I added the feature in my fork here for personal use. I'll be happy to send a PR here if it seems worth adding.

@MaazAli
Copy link
Author

MaazAli commented Mar 30, 2015

I think it's an important feature to have. Maybe others can chime in / the package author.

@gsuess
Copy link
Contributor

gsuess commented Mar 30, 2015

I do like the idea of the feature of returning meta data from the request.

However callbacks should not have more than two arguments in order to keep the convention: function (error, result) {}. We could still access it with upload.instructions.keyData.

As the key method on directive is specific to S3 and GoogleCloud, I would be in favour of a more generic name, .metaData perhaps?

Anyway, will need to figure out a neat way to fit this one in properly.

@abhishekbatra
Copy link

@gsuess I agree on both - 2 arguments and name for the return data variable. I'll try to do a clean up soon and then send a PR. Btw, my fork only does it for S3 at present.

@mxmzb
Copy link

mxmzb commented Feb 11, 2016

This would be a pretty cool feature (well, for me it's more than just cool, it's actually needed), kinda sad it's open since almost a year.

@tahaykNSM
Copy link

👍

@rpesciotta
Copy link

I vote for it as well. At the moment I also have to parse the downloadUrl in order to figure out what I need to update in the collection. Will be looking forward to an update ;)

@zeroasterisk
Copy link

I propose "extra" data could just be appended to the uploader object and used from there... I can get to some extra details already by lookin at the uploader, after upload:

  const uploader = new Slingshot.Upload('creativeUploads', creative);
  uploader.send(file, (error, downloadUrl) => {
    if (error) {
      // Log service detailed response.
      console.error('Error uploading', uploader.xhr.response);
      throw error;
    }
    console.log('uploader complete', uploader, downloadUrl);

  });

example of what it contains now (redacted a bit):

{"file":{
  "preview":"blob:http%3A//localhost%3A3000/186d57c7-4207-4606-8896-746a291de34f"
},
"instructions":{
  "upload":"https://s3.amazonaws.com/c.example.com",
  "download":"https://s3.amazonaws.com/c.example.com/x/H/z/xHz2G5WHeSM4TfQ5a-wt57354972537fd-thumb_large.jpg",
  "postData":[
    {
      "name":"key",
      "value":"x/H/z/xHz2G5WHeSM4TfQ5a-wt57354972537fd-thumb_large.jpg"
    },
    {
      "name":"bucket",
      "value":"example.com"
    },
    {
      "name":"Content-Type",
      "value":"image/jpeg"
    },
    {
      "name":"acl",
      "value":"public-read"
    },
    {
      "name":"Content-Disposition",
      "value":"inline; filename=\"wt57354972537fd-thumb_large.jpg\"; filename*=utf-8''wt57354972537fd-thumb_large.jpg"
    },
    {
      "name":"x-amz-security-token",
      "value":"xxxxxxx"
    },
    {
      "name":"x-amz-algorithm",
      "value":"AWS4-HMAC-SHA256"
    },
    {
      "name":"x-amz-credential",
      "value":"xxxxxxx/20160514/us-east-1/s3/aws4_request"
    },
    {
      "name":"x-amz-date",
      "value":"20160514T000000Z"
    },
    {
      "name":"policy",
      "value":"xxxxxxx"
    },
    {
      "name":"x-amz-signature",
      "value":"xxxxxxx"
    }
  ]
},
"xhr":{ }
}

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

7 participants