, benim denetleyicisi koduTek bir resmi kaydetmenin ve kullanıcının dropzone.js'yi kullanarak bir görüntüden daha fazlasını yapmasını engellemenin bir yolu var mı? Ben
[HttpGet]
public ActionResult Show(int? id)
{
string mime;
byte[] bytes = LoadImage(id.Value, out mime);
return File(bytes, mime);
}
[HttpPost]
public ActionResult Upload()
{
SuccessModel viewModel = new SuccessModel();
if (Request.Files.Count == 1)
{
var name = Request.Files[0].FileName;
var size = Request.Files[0].ContentLength;
var type = Request.Files[0].ContentType;
viewModel.Success = HandleUpload(Request.Files[0].InputStream, name, size, type);
}
return Json(viewModel);
}
private bool HandleUpload(Stream fileStream, string name, int size, string type)
{
bool handled = false;
try
{
byte[] documentBytes = new byte[fileStream.Length];
fileStream.Read(documentBytes, 0, documentBytes.Length);
Pictures databaseDocument = new Pictures
{
ProfilePicture=documentBytes,
FName=name,
Size=size,
Type=type
};
using(var contxt=new EnglisCenterEntities())
{
contxt.Pictures.Add(databaseDocument);
handled = (contxt.SaveChanges() > 0);
}
}
catch (Exception)
{
// Oops, something went wrong, handle the exception
}
return handled;
}
private byte[] LoadImage(int id, out string type)
{
byte[] fileBytes = null;
string fileType = null;
using(var contxt=new EnglisCenterEntities())
{
var databaseDocument = contxt.Pictures.FirstOrDefault(doc => doc.IdPicture == id);
if (databaseDocument != null)
{
fileBytes = databaseDocument.ProfilePicture;
fileType = databaseDocument.Type;
}
}
type = fileType;
return fileBytes;
}
var drobzone.js kullanıyorum veritabanında resim yüklemek için denemek ve bu benim komut
<script type="text/javascript">
$(document).ready(function() {
$("#preview").fadeOut(15);
$("#refreshButton").click(function() {
var imageToLoad = $("#imageId").val();
if (imageToLoad.length > 0) {
$("#preview").attr("src", "/Document/Show/" + imageToLoad);
$("#preview").fadeIn();
}
});
});
ve bu benim görünümüm
ve m ile çalışıyor ulti görüntüleri ama ben tek bir görüntü kaydetmek ve kullanıcı birden fazla resim koymak önlemek istiyorum. Tek bir resmi kaydetmenin ve kullanıcının dropzone.js'yi kullanarak bir görüntüden daha fazlasını yapmasını engellemenin bir yolu var mı?