MVC 5应用程序/照片上传在桌面上运行良好,但在移动设备上运行不正常

时间:2016-02-18 21:55:48

标签: asp.net-mvc azure mobile

我有一个MVC应用程序,它在Image实体中有一个Product模型和多个子图像,它们被上传到Azure Blob存储。这一切都适用于桌面,但不适用于移动浏览器。只是直接的MVC,没有Web API。

为什么移动浏览器无法将所选图像传递给控制器​​?

我再说一遍:这在几乎任何浏览器的桌面上都能正常工作......只是不能移动。

型号:

public class Image
{
    public int Id { get; set; }
    public string ImageGuid { get; set; }
    public string ImageUrl { get; set; }

    [Display(Name ="Image Title")]
    public string ImageTitle { get; set; }
    [Display(Name ="Image File")]
    public byte[] ImageFile { get; set; }
    public int ProductId { get; set; }
    public virtual Product product { get; set; }
}

查看(创建):

<input type="file" id="file" name="file" accept="image/*" />

控制器:

public ActionResult Create([Bind(Include = "Id,ImageGuid,ImageUrl,ProductId,ImageTitle,ImageFile")] Image image, HttpPostedFileBase file)
    {

//Yes... I know this might not be the best place for this block...
            if (file != null && file.ContentLength != 0)
            {
                string guid = System.Guid.NewGuid().ToString();
                image.ImageGuid = guid;
                CloudBlobContainer blobContainer = GetBlobContainer();


                //Get reference to the picture blob or create if not exists. 
                CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference(guid);

                //Save to storage
                blockBlob.UploadFromStreamAsync(file.InputStream);


                image.ImageUrl = blobContainer.Uri + "/" + image.ImageGuid;
            }            

        if (ModelState.IsValid)
        {
            db.Images.Add(image);
            db.SaveChanges();
            return RedirectToAction("Details", "Products", new { id = image.ProductId });
        }

        ViewBag.ProductId = new SelectList(db.Products, "Id", "ProductName", image.ProductId);
        return View(image);
    }

0 个答案:

没有答案