【问题标题】:Uploading large files using REST odata service by passing Base 64 of file通过传递文件的 Base 64 使用 REST odata 服务上传大文件
【发布时间】:2016-11-09 07:11:34
【问题描述】:

我想通过 REST odata 服务保存附件文件。我在服务中使用了实体框架。我将文件的 base 64 传递到其余客户端的主体中,如下所示:

服务调用网址:

http://localhost:20347/NewServices.svc/Attc(DocEntry=831,Image='',Password='',PType='',UserID='')

XML:

<?xml version="1.0" encoding="utf-8"?><entry xml:base="http://localhost:20347/NewServices.svc/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><id>http://localhost:20347/NewServices.svc/Attc(DocEntry=831,Image='',Password='',PType='',UserID='')</id><category term="Web_Services_Model.Attc" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" title="Attc" href="Attc(DocEntry=831,Image='',Password='',PType='',UserID='')" /><title /><updated>2016-11-08T10:58:41Z</updated><author><name /></author><content type="application/xml"><m:properties><d:DocEntrym:type="Edm.Int32">831</d:DocEntry><d:DocNumm:type="Edm.Int32">830</d:DocNum><d:U_ID>PID1058</d:U_PID><d:UID>1</d:UID><d:Act>138</d:Act><d:PType></d:PType><d:Image>BASE 64</d:Image><d:UserID>admin</d:UserID><d:Password></d:Password></m:properties</content></entry>

服务中用于保存图像文件的代码。

[ChangeInterceptor("OPDAttc")]
    public void SaveAttc(OPDAttc Atch, UpdateOperations operations)
    {
        #region Add

        if (operations == UpdateOperations.Add)
        {using (Image image = Image.FromStream(new MemoryStream(Convert.FromBase64String(ImgtoSave))))
                        {


                            image.Save(FileName + imageid + "_" + time_now + "_IMG.jpg", ImageFormat.Jpeg);

                            FileName = FileName + imageid + "_" + time_now + "_IMG.jpg";
                        }}
        WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.BadRequest;
        WebOperationContext.Current.OutgoingResponse.StatusDescription = Result;

        #endregion
    }

我解码base 64,将其转换回原始图像,然后保存在文件夹中。但我只能保存小文件。如果文件很大,我无法调用服务,因此无法保存文件。如何使用此服务以正确的格式正确保存任何类型的文件?通过此服务保存附件文件(各种大小的所有文件类型)的最佳且简单的方法是什么?

【问题讨论】:

    标签: c# entity-framework web-services odata


    【解决方案1】:

    我对 WCF 不是很熟悉,但我知道它的默认消息大小为 64k。如果这是您的问题,WCF - How to Increase Message Size Quota 的答案可能会对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2016-07-03
      • 2014-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-10
      • 2017-05-19
      • 2010-09-05
      • 1970-01-01
      相关资源
      最近更新 更多