Search code examples
c#node.jsimagexamarin.formsrefit

payload is too large when sending byte with refit


here is the client side error

 Refit.ApiException
   Message=Response status code does not indicate success: 413 (Payload Too 
   Large).
   Source=mscorlib
   StackTrace:
    at Refit.RequestBuilderImplementation+<>c__DisplayClass14_0`2[T,TBody]. 
   <BuildCancellableTaskFuncForMethod>b__0 (System.Net.Http.HttpClient client, 
   System.Threading.CancellationToken ct, System.Object[] paramList) [0x002bd] 
   in <cda9777f03ee4e9188064495e9f2e568>:0 
  at Kula.Addprofilepicture.Postbase (System.Byte[] base64strings) [0x0002b] in 
   C:\Users\blain\Desktop\Kula2\Kulaaa\Kula\Kula\Addprofilepicture.xaml.cs:81 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c. 
  <ThrowAsync>b__7_0 (System.Object state) [0x00000] in 
   <19853c43ab794d18ab1a33ecb65b3c4d>:0 
  at Android.App.SyncContext+<>c__DisplayClass2_0.<Post>b__0 () [0x00000] in 
   <8c07a09624c14764b43f6b946a5a1f23>:0 
  at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in 
  `enter code here` <8c07a09624c14764b43f6b946a5a1f23>:0 
   at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr 
   native__this) [0x00009] in <8c07a09624c14764b43f6b946a5a1f23>:0 
   at (wrapper dynamic-method) 
   Android.Runtime.DynamicMethodNameCounter.43(intptr,intptr)

server side error

 PayloadTooLargeError: request entity too large
    at IncomingMessage.onData 
    (C:\Users\blain\Desktop\KulaaBackend\node_modules\raw-body\index.js:246:12)
    at IncomingMessage.emit (events.js:210:5)
    at addChunk (_stream_readable.js:308:12)
    at readableAddChunk (_stream_readable.js:289:11)
    at IncomingMessage.Readable.push (_stream_readable.js:223:10)
    at HTTPParser.parserOnBody (_http_common.js:128:22)

server side code

app.post('/Phototest', (request, response) =>{
  console.log('request tried');
  console.log(request);

}) 

post byte code

    public async void Postbase(byte[] base64strings) {

            /*
            base64s s = new base64s()
            {
                base64string = base64strings

            };
            string stringpayload = JsonConvert.SerializeObject(s);
            await apiRequestHelper.RequestSaveProfilephotoAsync(stringpayload);
            */
            await myAPI.PostProfilePhoto(base64strings);

        }

here is the refit post i also stopped url encoding it because that might make it too large i think. so i am just sending it as a byte and nothing else. in the future i may need to send an email or token with it though.

 [Post("/Phototest")]
        Task<string> PostProfilePhoto(Byte[] data);

if you know of a better format to send it in that is shorter that would be awesome because i will have to pay for how much data i send to servers in future.


Solution

  • app.use(bodyParser.json({limit:'5000mb'})); app.use(bodyParser.urlencoded({limit:'5000mb',extended: true})); solved my problem