简体   繁体   中英

Is there a way to copy a blob from the local storage emulator to a remote azure storage?

I'm trying to copy a video file from the local azure storage, to a remote storage in C#, to be able to encode it using Azure Media Services.

After retrieving the blobs for the copy using the StartCopy method, I get a 404 NOT FOUNT exception returned.

destinationBlob.StartCopy(new Uri(sourceBlob.Uri.AbsoluteUri + signature));

The value of sourceBlob.Uri.AbsoluteUri is a local Uri ( http://127.0.0.1/ params)

I would expect the copy to be executed but instead I get a 404 Error.

Unfortunately you will not be able to accomplish this using Copy Blob functionality. The reason being Copy Blob operation is an async server-side operation and would require Storage Service to reach the copy source.

Since the copy source is a blob in the local emulator, Storage Service is not able to reach that and hence you're getting a 404 error.

What you would need to do is first download the blob from the emulator on your local computer and then upload the blob in cloud.

  • You need two connections to Azure storage.
  • You need to connect to your local video file in the emulator and treat it like a stream (call it localStream).
  • You then need to open you destination (remote) endpoint in Azure Storage and open it for Write as a stream (call it remoteStream)
  • You can then do a localStream.CopyTo(remoteStream);

This example allows you to pass in a Task to this function which accepts the Stream as an object to deal with. You will need to adjust the utils.GetBlockBlobReference to point to your actual blob reference. This method opens the stream for Wtire, you may also need one that opens a stream for reading. I've different providers for reading/writing to storage.

    public async Task Use(string pointer, Func<System.IO.Stream, Task> useAction)
    {
        if (useAction == null)
        {
            throw new ArgumentNullException(nameof(useAction));
        }

        var blobRef = await utils.GetBlockBlobReference(storageFactory, pointer);
        using (var cloudStream = await blobRef.OpenWriteAsync())
        {
            await useAction(cloudStream);
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM