openaq / openaq-upload

Batch uploader for OpenAQ
MIT License
2 stars 0 forks source link

Feature/upload #7

Closed nbumbarger closed 7 years ago

nbumbarger commented 8 years ago

@danielfdsilva @olafveerman

This PR adds the upload functionality to the parser. After selecting a file and clicking Validate CSV, the parser will convert the CSV to a JSON object and compare its attributes to the schema. If there are no errors, it will allow to proceed with the upload, if there are errors it will currently list them all in a scroll area. I added information about the S3 credential requirements to the README, and for now they can be provided by starting the server file.

nbumbarger commented 8 years ago

Hey @jflasher - I wanted to point you towards the way I'm currently handling Amazon uploads, and ask how you might want to handle it in production. Right now there is an API, launched from the server directory, which receives a filename to an endpoint called s3_credentials. The page uses the credentials it receives to sign a form including the upload file, which include the parameters: acl, key, policy, success_action_status, x-amz-algorithm, x-amz-credential, x-amz-date, and the file.

I imagine that in production you'll want to integrate this kind of endpoint with an existing API, correct? Are you planning to set that up? This implementation works fine if there's a place where it can be slotted in. There's also going to need to be an endpoint on which to validate the users' API keys. Let me know what you think when you have a chance.

jflasher commented 8 years ago

Hey @nbumbarger, thanks for looking into this. I haven't implemented any of this yet, but my thought is that on the frontend, you'd do something like api.openaq.org/v1/upload?token=USER_TOKEN&filename=FILENAME (where USER_TOKEN is the token we've given them and they put in the form and filename can be whatever you want) and it'd return something like

{
  "url": "SOME_PRESIGNED_URL"
}

Any errors (most likely wrong token) would lead to a 403 response.

You could then use that pre-signed url like in the response here. I'll probably end up using some of your code to generate that url or I think I can use the SDKs to do that as well. But you shouldn't need to worry about anything AWS specific from the frontend.

olafveerman commented 8 years ago

Thanks @nbumbarger Just tested it, couple of quick comments:

  1. after closing the validation modal, I'm not able to upload another file without refreshing the whole site
  2. could we have validation on the mandatory fields of the form with some nice feedback? If you don't specify a file for example, nothing happens.
  3. can we use node 6? It's the active LTS and we're slowly transitioning everything to it. Should be a quick change in the Readme and travis yml.

On Monday I'll do a more thorough review, focusing on how we're presenting the feedback to the users.

danielfdsilva commented 8 years ago

@olafveerman @nbumbarger Re changing to node 6: The only problem is that collecticons is not compatible with it, however we're not compiling icons here so it's ok.