Git Product home page Git Product logo

angular-azure-blob-upload's Introduction

angular-azure-blob-upload

AngularJS service for uploading to azure blob storage.

Provides for the ability to upload an HTML5 File to Azure's Blob Storage. The file is uploaded in chunks to avoid memory issues as a BlockBlob. The upload uses a Shared Access Signature (SAS) to secure the file upload.

Required dependencies

Add the Azure Blob Upload to your index.html file

<script src='/client/js/lib/azure-blob-upload.js'></script>

After downloading the azure-blob-upload.js to your AngularJS project then

Add 'azureBlobUpload' to your main angular.module like so

angular.module('myapp', ['myApp.controllers', 'myApp.services', 'azureBlobUpload']);

How to use

Add the azureBlob service as a dependency to your controller like so:

angular.module('myapp')
  .controller('MainCtrl', ['$scope', 'azureBlob', function ($scope, azureBlob) {
  ...
}])

This will expose the following method

  • azureBlob.upload(config)

The config object has the following properties

{
  baseUrl: // baseUrl for blob file uri (i.e. http://<accountName>.blob.core.windows.net/<container>/<blobname>),
  sasToken: // Shared access signature querystring key/value prefixed with ?,
  file: // File object using the HTML5 File API,
  progress: // progress callback function,
  complete: // complete callback function,
  error: // error callback function,
  blockSize: // Use this to override the DefaultBlockSize,
}

CORS

Cross Origin Resource Sharing (CORS) must be enabled on the azure blob storage account. The following articles can assist with this...

Windows Azure Storage Introducing CORS

Windows Azure Storage and CORS

Special Thanks

Extreme thanks goes to Gaurav Mantri and his original work using plain JavaScript. Much of it comes from the blob post... (http://gauravmantri.com/2013/02/16/uploading-large-files-in-windows-azure-blob-storage-using-shared-access-signature-html-and-javascript). I took his original code from here and turned it into a re-usable angular service.

Issues & Contribution

For questions, bug reports, and feature request please search through existing issue and if you don't find and answer open a new one here. If you need support contact me on twitter at @kinstephen

angular-azure-blob-upload's People

Contributors

fklingler avatar jaredgermano avatar kinstephen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-azure-blob-upload's Issues

CORS

Hi again. I have a suggestion, maybe you could add the CORS on the module itself since the request is done inside the module it will be confusing where to manage the CORS on browser side thank you. :)

Example

Thanks for your hard work creating this module. Would it be possible to create a working example for us newbies?

baseUrl property in config should be added "?"(Question mark) in the end.

Hello, I realized this angular module is very useful and I'm using it thankfully.

However, there seems to be having an issue while uploading file to blob storage.

I'm not sure whether you intended or not, but anyway the upload method does not work util I add "?" in the back of baseUrl property.

azureBlob.upload({
    baseUrl: "http://myaccount.blob.core.windows.net/mycontainer/myitem?",
    sasToken: sasQueryString,
    file: myfile,
    .......
});

I hope this would help your angular module.

Thanks.

Documentation of how to upload?

Thanks for putting this together. Can you post an example of how to upload? I see the config, but don't see how to actually get the upload working.
K.

Success and error functions are deprecated for newer angular versions

In newer versions of angular, the success and error functions, which were the legacy functions used by promises, are deprecated. As a result, these functions are not defined, and your code gives errors on lines 43, 53, 153, and 158.

There is already a pull request for the code change.

#14

Please review that request and make the change.

Thank you

405 (The resource doesn't support specified Http Verb.)

I am using the following to attempt to upload to Azure Blob storage along with the Angular Azure Blob Upload script, but am receiving a 405 (The resource doesn't support specified Http Verb.). If I change it to a PUT method, it gives me a Cross Origin error even though CORS is enabled and I am using a public container for testing purposes. Any clues? Is SAS required for upload, and if so, can you show an example of a config per your directive?

$scope.reRender = function () {
    var canvasImage = document.getElementById("c");
    var img = canvasImage.toDataURL("image/png");
    var filename = 'Test';

    var formdata = new FormData();
    formdata.append(filename, img);

    var send = function (blob) {
        var filename = 'Test.png';
        var formdata = new FormData();
        formdata.append('File1', blob, filename);

        $.ajax({
            url: 'http://myblob.blob.core.windows.net/blob1',
            type: "POST",
            data: formdata,
            mimeType: "multipart/form-data",
            processData: false,
            contentType: false,
            crossDomain: true,
            success: function (result) {
                console.log("Upload to Azure complete!");
            },
            error: function (error) {
                console.log("Something went wrong!");
            }
        })
    }

    var canvasImage = document.getElementById("c");
    if (!canvasImage.toBlob) {
        var dataURL = canvasImage.toDataURL();
        var bytes = atob(dataURL.split(',')[1])
        var arr = new Uint8Array(bytes.length);
        for (var i = 0; i < bytes.length; i++) {
            arr[i] = bytes.charCodeAt(i);
        }
        send(new Blob([arr], { type: 'image/png' }));
    }
    else
        canvasImage.toBlob(send);
}

Examples

Create an example dude else whats the point of sharing?

Multithreading Upload for Blob Upload

Dear Sir,

I started using angular-azure-blob-upload and to speed up the uploading speed i have configured the maximum blockSize of 4194304. Still it takes 2 minutes to upload 236 MB file size. So I'm are looking for an option to multithreaded upload. How to achive it using this component. Please Guide.

Thanks,
Viji

Add bower.json

Hey Stephen,

Could you register this with bower? Would be pretty cool to include this in webapp projects without downloading the file manually.

Andrew

Content Length not being set for the blobs on upload

This is a great project! It would be great if it was on bower!

I'm finding that the blobs once uploaded don't have their properties set, specifically length. Am I doing something wrong or is it missing a finalization step?

Working example

Hi I really like how the way you wrote the code for this, but I think you should add a working example for this? At least add some real-fake values to the config some users might now understand what they should put on the for example blockSize.

Safari and IOS File upload problem

Hello,
I have a problem when I am trying to upload a file in Safari and IOS. It gives me the following issue: FileConstructor is not a constructor (evaluating 'new File([blob], "png", {type: "image/png"})');
It seems like File is not supported by them. Do you think anybody can help me with that or have an alternative solution?
Just for reference, this is my code:
var blob = b64toBlob($scope.questionImgSrcCrop.split(",")[1], "image/png"); var file = new File([blob], "png", {type: "image/png"});

@kinstephen

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.