PDA

View Full Version : سوال: بررسی سایز ویدئو و فرمت آن با kendo mvc file upload



mansoure_p
شنبه 05 اسفند 1396, 11:39 صبح
من یک kendo mvc file upload دارم که با استفاده از آن میخوام ویدئو آپلود کنم ولی میخوام تا یک حجمی کاربر بتونه فایل آپلود کنه و مثلا چند تا فرمت، مثل mp4 ,flv,wmv . من از contentlength استفاده کردم ولی کار نکرد،در ضمن کندو من 2016 هست.و سوال دیگه استفاده از تگ ویدئو برای نمایش فرمت هایی که گفتم.

من تو وب کانفیگ تا حجم 100mb رو مجاز کردم
<requestFiltering>
<!-- The content length is in bytes -->
<requestLimits maxAllowedContentLength="104857600" />
</requestFiltering>
<httpRuntime targetFramework="4.5" executionTimeout="3000" maxRequestLength="102400" />


اینم کنترلرم هست

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(Videos videos, HttpPostedFileBase VideoUrl)
{
if (ModelState.IsValid)
{
if (VideoUrl != null)
{
if (videos.VideoUrl != "no-video.jpg")
{
if (System.IO.File.Exists(Server.MapPath("/Videos/galleryvideos/" + videos.VideoUrl)))
System.IO.File.Delete(Server.MapPath("/Videos/galleryvideos/" + videos.VideoUrl));
}

videos.VideoUrl = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(VideoUrl.FileName);
VideoUrl.SaveAs(Server.MapPath("/Videos/galleryvideos/" + videos.VideoUrl));

}

db.Entry(videos).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(videos);
}
واینم view:


@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">

<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.VideoID)
@Html.HiddenFor(model => model.CreateDate)
<div class="hide">
@Html.HiddenFor(model=>model.VideoUrl)
</div>
<div class="form-group">
@Html.LabelFor(model => model.VideoTitle, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.VideoTitle, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.VideoTitle, "", new { @class = "text-danger" })
</div>
</div>

<div class="form-group">
@Html.LabelFor(model => model.VideoUrl, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.Kendo().Upload().Name("VideoUrl").Multiple(false)
<br/>
<video alt="Videos" class="thumbnail" width="320" height="240" controls>
<source src="~/Videos/galleryvideos/@Model.VideoUrl" type="video/mp4">
<source src="~/Videos/galleryvideos/@Model.VideoUrl" type="video/ogg">
</video>
<br/>
<p class="help-block">لطفا ویدیوها را با حجم کمتر از 100 مگابایت و با پسوند mp4 ارسال کنید</p>

</div>
</div>



<div class="form-group" id="buttons">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="ثبت" class="btn btn-primary" />
@Html.ActionLink("بازگشت به فهرست", "Index")
</div>
</div>
</div>
}