我不懂VB,所以希望这段C#代码对你有所帮助。
首先,我从未使用过 amazon-s3,因此我不会提供具体示例,但是在进行快速搜索时,我发现了另一个线程,其中用户指出了如何将图像实际上传到amazon 使用内存流here。
一个选项是创建一个上传操作服务器端,这是使用 MVC 在 C# 中的 sn-p:
[HttpPost]
public ActionResult UploadImage(HttpPostedFileBase file)
{
// TODO: your validation goes here,
// eg: file != null && file.ContentType.StartsWith("image/") etc...
var imageUrl = _myAmazonWrapper.UploadImage(file.InputStream);
return Json(imageUrl);
}
此操作结果将收到一个 HttpPostedFileBase 图像,其中包含具有内容类型、文件名等的实际图像。
最后剩下的就是summernote脚本的实际初始化了:
$('#summernote').summernote({
onImageUpload: uploadImages
});
其中函数uploadImages可以定义如下:
var uploadImages = function (files, editor, $editable) {
var formData = new FormData();
formData.append("file", files[0]);
$.ajax({
url: "Image/UploadImage",
data: formData,
type: 'POST',
cache: false,
contentType: false,
processData: false,
success: function (imageUrl) {
if (!imageUrl) {
// handle error
return;
}
editor.insertImage($editable, imageUrl);
},
error: function () {
// handle error
}
});
};
请注意,uploadImage 函数不支持多张图片,例如,您可以将图片拖放到 summernote 小部件,在这种特殊情况下,“files”参数将包含多张图片,因此只需枚举它们并上传随意。
祝你好运!