1

I am at learning phase of web api and I want to upload image to server using web api in mvc dot net. I have tried much but not getting solution.

In controller I have done this.

string img = username + "_" + labTestId + fb;
var element2 = image;
MemoryStream ms = new MemoryStream(Convert.FromBase64String(element2));
byte[] imagesbytes = ms.ToArray();
string folder_name = "lab-orders";
folder_name = folder_name.ToLower();
string SaveLocation = ServerConfig.BlobPath + folder_name + "/" + fb+imagesbytes;
BlobUploader.UploadTo(folder_name,img, ms);

//   var filePath = HttpContext.Current.Server.MapPath("~/Userimage/" + postedFile.FileName + extension);
var filePath = HttpContext.Current.Server.MapPath(SaveLocation + postedFile.FileName + extension);

postedFile.SaveAs(filePath);

How can I upload image to server using web api?

2
  • Can you shere whole action? Where are You trying to uploafd image? To azure blob storage? Commented Jan 11, 2018 at 9:01
  • yes to azure blob storrage i want to upload using web api Commented Jan 11, 2018 at 9:04

1 Answer 1

1

It's not that simple.

In this tutorial You have step by step everything You have to do, to upload image.

In brief:

  1. Create Blob Storage Account, and get access keys.

  2. Save keys in Your web config.

  3. Install WindowsAzureStorage from nuget packege manager Create blob storage client, get or create blob container

  4. create CloudBlockBlob and upload it.

Edit Change link to web api tutorial insted of mvc tutorial

Sign up to request clarification or add additional context in comments.

1 Comment

If this answer helped You, please mark it as such if it was helpful using the checkbox next to it @SoftwareStudent

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.