Blob通过ajax发送,通过VB接收

Blob sent through ajax receive through VB

本文关键字:通过 VB 接收 发送 ajax Blob      更新时间:2023-09-26

我现在有点卡住了。我的VB脚本不读取图像blob,或者不获得文件。我希望你们都能帮忙。这是我的代码。

这里的图像已经是base64格式,并且已经被转换为blob并添加到表单

var blob = dataURItoBlob(final_image.src);
var formData = new FormData();
formData.append("objFile", blob, "image.jpeg");
$.ajax({
    url: 'UploadImage/ ImageFunction',
    data: { IDName: sessionStorage.IDName, CanvasImage: formData },
    cache: false,
    processData: false,
    contentType: false,
    type: 'POST'
});

正如你在这里看到的,它现在被发送到vb脚本。问题是它不读取blob文件,也不保存。

Function ImageFunction()
    Dim directory As String
    Dim objFile As HttpPostedFileBase = Request.Files("objFile")
    Dim counter As Integer = Request.Files.Count
    If Not System.IO.Directory.Exists("temp'Pictures") Then
        IO.Directory.CreateDirectory("temp'Pictures")
    End If
    directory = "temp'Pictures'"
    If Not System.IO.Directory.Exists(directory & Common.WebRequest.Data("IDName")) Then
        IO.Directory.CreateDirectory(directory & Common.WebRequest.Data("IDName"))
    End If
    If (Not objFile Is Nothing) Then
        objFile.SaveAs(directory & Common.WebRequest.Data("IDName") & "'" & Common.WebRequest.Data("IDName") & ".jpg")
    End If
End Function
谁能告诉我我哪里错了?

看看这个问题:

使用jQuery's ajax方法作为blob检索图像

如果有必要使用ajax,也许你需要使用原生XMLHttprequest。

我希望有帮助!