Upload file to Azure Blob Storage directly from browser?

后端 未结 5 843
北海茫月
北海茫月 2020-12-08 10:43

Is it possible to create an html form to allow web users to upload files directly to azure blob store without using another server as a intermediary? S3 and GAW blobstore b

5条回答
  •  [愿得一人]
    2020-12-08 10:58

    EDIT November 2019

    You can now refer to the official documentation:

    • Azure Storage JavaScript Client Library Sample for Blob Operations
    • Azure Storage client library for JavaScript

    Initial answer

    There is a New Azure Storage JavaScript client library for browsers (Preview).

    (Everything from this post comes from the original article above)

    • The JavaScript Client Library for Azure Storage enables many web development scenarios using storage services like Blob, Table, Queue, and File, and is compatible with modern browsers
    • The new JavaScript Client Library for Browsers supports all the storage features available in the latest REST API version 2016-05-31 since it is built with Browserify using the Azure Storage Client Library for Node.js

    We highly recommend use of SAS tokens to authenticate with Azure Storage since the JavaScript Client Library will expose the authentication token to the user in the browser. A SAS token with limited scope and time is highly recommended. In an ideal web application it is expected that the backend application will authenticate users when they log on, and will then provide a SAS token to the client for authorizing access to the Storage account. This removes the need to authenticate using an account key. Check out the Azure Function sample in our Github repository that generates a SAS token upon an HTTP POST request.

    Code sample:

    1. Insert the following script tags in your HTML code. Make sure the JavaScript files located in the same folder.

      
      
      
    2. Let’s now add a few items to the page to initiate the transfer. Add the following tags inside the BODY tag. Notice that the button calls uploadBlobFromText method when clicked. We will define this method in the next step.

      
      
      
    3. So far, we have included the client library and added the HTML code to show the user a text input and a button to initiate the transfer. When the user clicks on the upload button, uploadBlobFromText will be called. Let’s define that now:

      
      

提交回复
热议问题