0

I want to save an attachment file through REST odata service. I have used entity framework in service. I am passing base 64 of file into body of rest client as follows:

Service call url:

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>

Code used in service to save image file.

[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
    }

I decode base 64, convert it back to original image and then save in folder. But only small size files I can save. If a file is large, I am unable to call the service and hence unable to save the file. How can I use this service to save any type of file properly on correct format? What would be the best and easy way to save an attachment file (all file types of all sizes) through this service?

halfer
  • 19,824
  • 17
  • 99
  • 186
Pwavel002
  • 279
  • 2
  • 10

1 Answers1

0

I'm not really familiar with WCF, but I know that it has a default message size of 64k. If that's your problem, the answer(s) from WCF - How to Increase Message Size Quota might help you.

halfer
  • 19,824
  • 17
  • 99
  • 186
Jürgen Röhr
  • 886
  • 6
  • 10