Cloud API with JavaScript (Amazon, Azure)

前端 未结 5 1986
遇见更好的自我
遇见更好的自我 2021-02-14 06:50

I\'m researching a possibility of using some cloud storage directly from client-side JavaScript. However, I ran into two problems:

  1. Security - t

相关标签:
5条回答
  • 2021-02-14 07:19

    Windows Azure Blob Storage has the notion of a Shared Access Signature (SAS) which could be issued on the server-side and is essentially a special URL that a client could write to without having direct access to the storage account API key. This is the only mechanism in Windows Azure Storage that allows writing data without access to the storage account key.

    A SAS can be expired (e.g., give user 10 minutes to use the SAS URL for an upload) and can be set up to allow for canceling access even after issue. Further, a SAS can be useful for time-limited read access (e.g., give user 1 day to watch this video).

    If your JavaScript client is also running in a browser, you may indeed have cross-domain issues. I have two thoughts - neither tested! One thought is JSONP-style approach (though this will be limited to HTTP GET calls). The other (more promising) thought is to host the .js files in blob storage along with your data files so they are on same domain (hopefully making your web browser happy).

    The "real" solution might be Cross-Origin Resource Sharing (CORS) support, but that is not available in Windows Azure Blob Storage, and still emerging (along with other HTML 5 goodness) in browsers.

    0 讨论(0)
  • 2021-02-14 07:21

    This can be done with Amazon S3, but not Azure at the moment I think. The reason for this is that S3 supports CORS.

    http://aws.amazon.com/about-aws/whats-new/2012/08/31/amazon-s3-announces-cross-origin-resource-sharing-CORS-support/

    but Azure does not (yet). Also, from your question it sounds like a queuing solution is what you want which suggests Amazon SQS, but SQS does not support CORS either.

    If you need any complex queue semantics (like message expiry or long polling) then S3 is probably not the solution for you. However, if your queuing requirements are simple then S3 could be suitable.

    You would have to have a web service called from the browser with the desired S3 object URL as a parameter. The role of the service is to authenticate and authorize the request, and if successful, generate and return a URL that gives temporary access to the S3 object using query string authentication.

    http://docs.aws.amazon.com/AmazonS3/latest/dev/S3_QSAuth.html

    A neat way might be have the service just redirect to the query string authentication URL.

    For those wondering why this is a Good Thing, it means that you don't have to stream all the S3 object content through your compute tier. You just generate a query string authenticated URL (essentially just a signed string) which is a very cheap operation and then rely on the massive scalability provided by S3 for the actual upload/download.

    Update: As of November this year, Azure now supports CORS on table, queue and blob storage

    http://msdn.microsoft.com/en-us/library/windowsazure/dn535601.aspx

    0 讨论(0)
  • 2021-02-14 07:25

    Yes you can do this but you wouldn't want your azure key available on the client side for the javascript to be able to access the queue directly.

    I would have the javascript talking to a web service which could check access rights for the user and allow/disallow the posting of a message to the queue.

    So the javascript would only ever talk to the web services and leave the web services to handle talking to the queues.

    Its a little too big a subject to post sample code but hopefully this is enough to get you started.

    0 讨论(0)
  • 2021-02-14 07:25

    With Amazon S3 and Amazon IAM you can generate very fine grained API keys for users (not only clients!); however the full would be PITA to use from Javascript, even if possible.

    However, with CORS headers and little server scripting, you can make uploads directly to the S3 from HTML5 forms; this works by generating an upload link on the server side; the link will have an embedded policy document on, that tells what the upload form is allowed to upload and with which kind of prefix ("directories"), content-type and so forth.

    0 讨论(0)
  • 2021-02-14 07:27

    I think that the existing service providers do not allow you to query storage directly from the client. So in order to resolve the issues:

    1. you can write a simple Server and expose REST apis which authenticate based on the APIKey passed on as a request param and get your specific data back to your client.
    2. Have an embedded iframe and make the call to 2nd domain from the iframe. Get the returned JSON/XML on the parent frame and process the data.

    Update: Looks like Google already solves your problem. Check this out.

    On https://developers.google.com/storage/docs/json_api/v1/libraries check the Google Cloud Storage JSON API client libraries section.

    0 讨论(0)
提交回复
热议问题