我正在尝试使用backload (https://github.com/blackcity/Backload)将图片上传到我们目前正在构建的一个mvc应用程序。它应该能够将图像存储在数据库中,但我没有找到演示此功能的示例。
有没有人知道这件事?
谢谢
发布于 2013-11-29 20:58:21
我有一个类似的需求,不想使用entityframework,所以我是这样处理的:
自定义控制器:
public async Task<ActionResult> UploadImage()
{
FileUploadHandler handler = new FileUploadHandler(Request, this);
handler.StoreFileRequestFinished += handler_StoreFileRequestFinished;
ActionResult result = await handler.HandleRequestAsync();
return result;
}事件处理程序方法:
void handler_StoreFileRequestFinished(object sender, StoreFileRequestEventArgs e)
{
//I know I am only expecting 1 file...
var file = e.Param.FileStatus.Single();
//Call my service layer method to insert the image data
//You could base64 encode the stram here and insert it straight in the db
service.InsertProductImage(
int.Parse(e.Param.CustomFormValues["ProductID"]),
file.FileName,
file.FileUrl,
Server.MapPath(new Uri(file.FileUrl).PathAndQuery),
int.Parse(e.Param.CustomFormValues["FileTypeID"]),
int.Parse(e.Param.CustomFormValues["ColourID"]),
Current.User().UserID
);
}视图中的Javascript上载
$('#Form_FocusGraphic').fileupload({
url: "/Product/UploadImage",
acceptFileTypes: /(jpg)|(jpeg)|(png)|(gif)$/i,
fileInput: $('input#FocusGraphicInput'),
maxFileSize: 5000000, //5mb
formData: [{ name: 'ProductID', value: '@Model.ProductID' }, { name: 'FileTypeID', value: '3' }, { name: 'ColourID', value: '0' }, { name: 'uploadContext', value: "3;0" }],
start: function (e, data) {
$('img#FocusImage').attr('src', '/Content/img/largeSpinner.gif');
},
done: function (e, data) {
var obj = jQuery.parseJSON(data.jqXHR.responseText);
$('img#FocusGraphic').attr('src', obj.files[0].url);
}
});所以它所做的就是向控制器发送一个请求(传入一些特定的自定义参数),然后我将一个自定义事件附加到FileUploadHandler以调用"StoreFileRequestFinished“上的自定义处理程序,这实际上非常简单。
发布于 2013-08-08 05:20:08
我们在我们的商业产品中使用数据库功能。我不得不说,我们使用的是为我们开发的自定义版本。据我所知,数据库功能只适用于企业版,以及源代码和支持。它不便宜,但值得一试。
点击此处阅读:https://github.com/blackcity/Backload/wiki/Configuration#database-configuration-element
https://stackoverflow.com/questions/18113424
复制相似问题