question

FOJIPETMART-6263 avatar image
0 Votes"
FOJIPETMART-6263 asked FOJIPETMART-6263 commented

Image not getting uploaded

Not able to upload image from my App. I am using an api do upload the image through mobile but getting error all time . The same piece of code is working fine in Bigrock Server and on my local too . I am Uploading the image as body Multipart . I am giving u the Url , error msg and image uploading api code below.

URL -- https://onpetapi.azurewebsites.net/User/updateUser?userId=a9033a69-5916-49be-ba13-2269aaffa0ae&Name=Admin&PhoneNumber=8859984497 (Images are sent in Body )

Error Mg ---- Error writing MIME multipart body part to output stream."

Api Souce Code --

[Route("User/updateUser")]
public async Task<IHttpActionResult> updateUser(Guid userId, string Name, string PhoneNumber)
{
var uploadPath = "";
try
{
var userExist = db.Users.Where(w => w.Id == userId && w.IsActive == true).SingleOrDefault();
if (userExist != null)
{
var _uploadedDataId = userId;
var _exfilename = _uploadedDataId;

                 var httpRequest = HttpContext.Current.Request;

                 if (httpRequest.Files.Count != 0)
                 {

                     uploadPath = System.Web.HttpContext.Current.Server.MapPath("~/storage/Uploads");
                     var multipartFormDataStreamProvider = new UploadMultipartFormProvider(uploadPath);

                     await Request.Content.ReadAsMultipartAsync(multipartFormDataStreamProvider);

                     string _localFileName = multipartFormDataStreamProvider
                         .FileData.Select(multiPartData => multiPartData.LocalFileName).FirstOrDefault();

                     string filePath = string.Empty;
                     string newfilePath = string.Empty;

                     filePath = uploadPath + '/' + Path.GetFileName(_localFileName);
                     string extension = Path.GetExtension(_localFileName);
                     string filename = Path.GetFileName(_localFileName);
                     newfilePath = uploadPath + '/' + _uploadedDataId + filename + extension;

                     File.Move(filePath, newfilePath);



                     userExist.Name = Name;
                     userExist.Phone = PhoneNumber;
                     userExist.ProfilePic = Common.Constants.FileUpload.FlateFilePath +"/storage"+"/Uploads/" + _uploadedDataId + filename + extension;
                     userExist.ModifiedDate = DateTime.Now;

                     db.SaveChanges();
                 }
                 else
                 {
                     userExist.Name = Name;
                     userExist.Phone = PhoneNumber;
                     userExist.ModifiedDate = DateTime.Now;
                     db.SaveChanges();
                 }


                // return Ok("User Details SuccessFully Updated");
                 return Ok(uploadPath);
             }
             else
             {
                 return Ok("User either Doesn't Exists or is currently inActive !!");
             }
         }
         catch (Exception ex)
         {

            // return BadRequest(ex.Message);
             return Ok(uploadPath);
         }
     }
azure-functions
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @FOJIPETMART-6263 - Have you looked into if the destination folder has the required permissions? Personally, I think that Azure Blob storage would be a more idiomatic way to do it.

0 Votes 0 ·

Hi Mike Urnun,
I have given all the permission guided by the chat support .
Azure Blob storage would be a more idiomatic way to do it --->> what does it mean , whether i need to change my image upload Code ? . Pls guide , everything ok for me but stuck while uploading the image.
Thanks.

0 Votes 0 ·

0 Answers