画像アップロードフォームがあります
<% using (Html.BeginForm("PictureValidateAndSave", "UserGallery", new {}, FormMethod.Post, new { enctype = "multipart/form-data"})) { %>
<table>
<tr>
<td> Album Name: </td>
<td> <%= Html.DropDownList("albumList") %></td>
</tr>
<tr>
<td> File Location: </td>
<td> <input type="file" name="picture" accept="image/gif, image/jpeg" /> </td>
<tr>
<tr>
<td> Picture name: </td>
<td> <input name="pictureName" style="width: 147px;"/> </td>
</tr>
</table>
<p> <input type="submit" value="Save" /> </p>
<% } %>
それはアクションに戻って投稿します
public ActionResult PictureValidateAndSave(long albumList, HttpPostedFileBase picture, string pictureName)
このコードは、Google Chrome を除くすべてのブラウザーで機能します。私の IDE は Visual Studio 2k8 です。Google Chrome でデバッグする方法がわかりませんが、エラー メッセージが表示されます。Chrome では何らかの理由で次のチェックに合格しないことがわかっています。
string mimeType = picture.ContentType;
// Check for the correct mimeType to define the extension
switch (mimeType)
{
case "image/pjpeg":
mimeType = ".jpeg";
break;
case "image/png":
mimeType = ".png";
break;
case "image/x-png":
mimeType = ".png";
break;
case "image/gif":
mimeType = ".gif";
// Conversion to image
Image gifImage = Image.FromStream(picture.InputStream);
FrameDimension dimension = new FrameDimension(gifImage.FrameDimensionsList[0]);
int frameCount = gifImage.GetFrameCount(dimension);
// Reject if its an animated gif
if (frameCount > 1)
{
return RedirectToAction("UploadPicture", new { error = 3 });
}
break;
default:
return RedirectToAction("UploadPicture", new { error = 1 });
}
どうやら、Chrome では、HttpPostedFileBase パラメーターの画像が正しくエンコードされておらず、MIME タイプが失われているようですが、これだけが問題ではない可能性があります。Chrome での HttpPostedFileBase パラメータの何が問題なのですか?どうすれば修正できますか?
ご清聴ありがとうございました。ご協力いただきありがとうございます。