3
votes

We are currently in the process of migrating old user data which is stored on one of our dedicated servers or locally on a ionic mobile application to Azure (or both). We have completed the migration of basic table data as well as images which are located on the device. The problem we are experiencing is transferring images from the old dedicated server to Azure Blob Storage WITHOUT downloading the image to the device before uploading (due to data usage concerns).

USE CASE:

1) User logs into the updated mobile app/website.

2) User data is moved from old server to Azure in a "sync" step.

3) All local images are uploaded to Azure blob using SAS query string generated by Azure.

4) All images that no longer exist locally need to be moved to azure blob storage from the dedicated server

PROBLEM:

Is it possible to move these files without downloading them to the device first and then uploading them. The current system is a VB.NET MVC application. I have seen references to the Azure Blob Storage SDK but from what I can see it is only available as a C# library.

CURRENT IDEAS:

1) Build a C# application that uses the Storage SDK to copy files to blob storage. Not sure how you would use the SAS query string in this case. Also how to monitor the status of the uploads and relay back to the app/website?

2) Download images to device first and then upload normally using SAS query string

Any help or suggestions would be greatly appreciated. Thank you for your time.

1
2 Questions: 1) Are these images publicly available i.e. if I have the URL of an image and I put that in a browser's address bar, will I be able to view the image? 2) Are you storing these image URLs in some database? - Gaurav Mantri
Hi Gaurav, thanks for your response. 1) Yes they are publicly available 2) Yes the image URL's are constructed from data contained within a database - JSS025

1 Answers

0
votes

Is it possible to move these files without downloading them to the device first and then uploading them. The current system is a VB.NET MVC application. I have seen references to the Azure Blob Storage SDK but from what I can see it is only available as a C# library.

As far as I know, we couldn't directly copy url directly in blob storage without downloading them to the device first and then uploading them.

The azure storage blob support server side copy from the another blob or file content by using Copy Blob rest api command.

The azure SDK also execute the StartCopy method which will send the request by using Copy Blob rest api. So we couldn't directly copy url directly in blob storage without downloading them to the device first and then uploading them.

Download images to device first and then upload normally using SAS query string

I suggest you could try to download the images to your local's memorystream firstly, then upload the blob from stream.

After uploading you could release this stream.

More details, you could refer to below code sample:

 string blobContainerSasUri = "";

            string filename = "";

            string filepathurl = "";

            CloudBlobContainer container = new CloudBlobContainer(new Uri(blobContainerSasUri));         
            CloudBlockBlob blockblob = container.GetBlockBlobReference(filename);

            using (var client = new HttpClient())
            {
                //get the url 
                var request = new HttpRequestMessage(HttpMethod.Get, "filepathurl");
                var sendTask = client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);
                var response = sendTask.Result;

                HttpStatusCode status = response.StatusCode;
                if (status == HttpStatusCode.OK)
                {
                    var httpStream = response.Content.ReadAsStreamAsync().Result;
                    MemoryStream ms = new MemoryStream();
                    httpStream.CopyTo(ms);
                    ms.Position = 0;
                    blockblob.UploadFromStream(ms);
                }
            }