Beispiel #1
0
        public async Task <IActionResult> UploadBlobProductImage([FromForm] FileUpload objFile)
        {
            try
            {
                if (objFile.files.Count > 0)
                {
                    var data = objFile.productPhotoData;

                    ProductPhoto itemContainer = JsonConvert.DeserializeObject <ProductPhoto>(data);
                    ProductPhoto item          = itemContainer;
                    item.productPhotoId = Guid.NewGuid();

                    var    files    = objFile.files;
                    string fileName = files[0].FileName;

                    string uri = await _azureBlobService.UploadAsyncProductPhoto(files, item.productVariantId.ToString());

                    item.PhotoURL = uri;
                    await ProductHandler.CreateProductPhotoMediaFile(item);

                    return(Ok("Image successfully uploaded"));
                }
                else
                {
                    return(StatusCode(505, "CS API Error: No files were recieved for upload, upload failed"));
                }
            }
            catch (Exception ex)
            {
                string errorMessage = handleCatch(ex);
                return(StatusCode(505, errorMessage));
            }
        }