使用C#读取附加到HTTP扩展的BLOB

拉胡尔·沙玛(Rahul Sharma)

因此,我正在使用第三方服务,该服务可让我编辑XML存储在服务器路径上的文件。现在,完成编辑后XML,我将文件保存到本地存储器中,该存储器会生成附加到URL的BLOB。

例:

blob:http://localhost/0e06af7a-a1a9-4bf1-a79a-78a1e107648f

其中0e06af7a-a1a9-4bf1-a79a-78a1e107648f是为当前编辑创建的令牌。现在,当我在浏览器中运行上述URL时,可以看到:

在此处输入图片说明

我的问题是:如何使用C#读取上面的URL,然后将内容保存到对象中,以便以后用于上载到文件或云中。我试过使用WebClient

WebClient client = new WebClient();
Stream stream = client.OpenRead("blob:http://localhost/0e06af7a-a1a9-4bf1-a79a-78a1e107648f");
StreamReader reader = new StreamReader(stream);
string str= reader.ReadToEnd();

但这给了我一个错误,说的URL不正确,应以HTTP开头HTTPS

编辑:我能够使用JQuery将Blob保存到文件:

var download = $('<a>Download ' + "file.xml" + '</a>').attr("href", "blob:http://localhost/0e06af7a-a1a9-4bf1-a79a-78a1e107648f");
download.attr("download", "file.xml");

这将成功创建一个名为的文件file.xml并下载该文件。我希望将此blob内容保存在服务器端,以便可以将其发送到Amazon S3存储桶。

再次编辑:

因此,当前我将XMLas保存为字符串,并且尝试通过AJAX将其发送到C#控制器,但遇到500内部服务器错误。

        var xmlString = self.xml2Str(self.xmlState.xml);
        //console.log(xmlString);
        var blob = new Blob([xmlString], { type: "text/xml" }); 
        console.log(blob);
        var url = URL.createObjectURL(blob);
        console.log(url);
        var json = {
            xmlString: xmlString
        };

        var test = JSON.stringify(json);
        console.log(test);

        try {
            $.ajax({
                url: BaseURL + "Home/SendXMLToS3",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                data: { "json": test},
                type: "POST",
                success: function (data) {
                    //TODO: Add whatever if you want to pass a notification back
                    alert("Done");
                },
                error: function (error) {
                    //TODO: Add some code here for error handling or notifications
                    alert("Not Done");
                }
            });
        }
        catch (err) {
            console.log(err);
        }

test变量的内容如下(从控制台):

{"xmlString":"<nitf>\n  <head>\n    <docdata>\n      <identified-content>\n        <classifier id=\"box-geometry\" value=\"147,623,250,790\" />\n        <classifier id=\"uuid\" value=\"Mv8XVAViEeqyc3SUunSxMg\" />\n      </identified-content>\n    </docdata>\n  </head>\n  <body>\n    <body.head />\n    <body.content>\n      <p>\n        <lang fontStyle=\"regular\" style=\".Bodylaser\">How is this different from Pegasus?</lang>\n      </p>\n      <p>\n        <lang fontStyle=\"regular\" style=\".Bodylaser\">Pegasus could be installed on your phone without your knowledge through just a missed WhatsApp video call. In the case of the new breach, a user has to manually download the MP4 file sent to them before any malicious code can be run. The problem is not with WhatsApp’s end-to-end encryption feature here. Getting remote access to your phone is the equivalent of actually holding it in one’s hand. End-to-end encryption is meant to stop attackers from stealing or snooping on chats in between. So, unless someone has access to your device, they can’t actually read your chats, even if they intercept them.</lang>\n      </p>\n    </body.content>\n  </body>\n</nitf>"}

还尝试将默认ASP.NET设置为默认启用请求验证,以帮助防止XSS设置为false。

    [HttpPost]
    [ValidateInput(false)]
    public ActionResult SendXMLToS3(string json)

仍然存在相同的500错误:jquery.min.js:4 POST http://localhost/DEGit/Home/SendXMLToS3 500 (Internal Server Error)h.send(c.hasContent&&c.data||null)方法中。

我怎么能够:

  1. 读取blobC#中生成的URL内容?
  2. test通过AJAX字符串发送到C#吗?
  3. 你们还有其他建议。

谢谢

贾瓦德·谢赫(Jawad Al Shaikh)

正如您在评论中所要求的:我制作了简单的控制器和JS代码,以httppost使用ajax在控制器内命中一个方法:

  1. 控制器方法:
[HttpPost]
public JsonResult SendXMLToS3(string json)
{
    return Json(new { Result = "PASS", Message = "testing SendXMLToS3" });
}
  1. JS代码:
<script type="text/javascript">
    function myfunction() {

        var test = { "xmlString": "<nitf>...</nitf>" };
        $.ajax({
            type: "post",
            url: "/Home/SendXMLToS3",
            dataType: "json",
            data: { "json": test },
            success: function (res) {
                alert(res.Message);
            },
            error: function (res) {
                //TODO: Add some code here for error handling or notifications
                alert("Not Done");
            }
        });
    }
</script>

结果
该行contentType: "application/json; charset=utf-8",引起了Internal 500错误,如果将其删除,应该没问题。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

从C#外部读取NAV压缩的Blob

来自分类Dev

将文件附加到C#中的电子邮件

来自分类Dev

C#空文件,当附加到MailMessage对象时

来自分类Dev

Javascript。附加到Blob

来自分类Dev

使用PHP,如何将JSON Blob附加到现有的多级JSON对象

来自分类Dev

如何使用asp.net c#将使用jsPDF生成的PDF附加到邮件中

来自分类Dev

如何使用C#从Firebird读取二进制Blob到byte []?

来自分类Dev

附加到Azure Blob时的HTTP 400:错误请求

来自分类Dev

c ++附加到链表

来自分类Dev

是否可以使用Python tarfile读取并附加到tar

来自分类Dev

使用C#将JSON字符串直接添加到Azure Blob存储容器

来自分类Dev

如何将Blob附加到FormData

来自分类Dev

如何将Blob附加到dom?

来自分类Dev

C:无法从附加到子进程的stdout的管道读取

来自分类Dev

附加到C#中的列表

来自分类Dev

使用数组C#附加子项

来自分类Dev

如何使用C#从Firebird读取二进制Blob到byte []?

来自分类Dev

附加到Azure Blob时的HTTP 400:错误请求

来自分类Dev

如何选择并将MSSQL附加到C#代码

来自分类Dev

通过API从C#附加到$ PSModulePath

来自分类Dev

如何在C#中使用Enyim.Caching将数据附加到memcached?

来自分类Dev

子节点未附加到节点 XML C#

来自分类Dev

C# 删除 ListChanged 事件附加到 Bindingsource

来自分类Dev

C# - 将 XElement 数组附加到 XElement

来自分类Dev

将元素附加到扩展列表

来自分类Dev

C# 将文本附加到特定行

来自分类Dev

如何使用 C# 中的 Azure 函数读取 blob 输入绑定中的 XML 文件?

来自分类Dev

如何使用 Node.js SDK 从 Azure Blob 存储读取附加 Blob 到字符串?

来自分类Dev

我想使用 c# 将新创建的控件附加到 ListBoxItem 控件

Related 相关文章

热门标签

归档