1

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.

  • Try to console.log `request.body` to check if it has any data at all. – Shihab Dec 03 '19 at 11:30
  • who is saying the request is too long? Is it a server error or a client error? – Jason Dec 03 '19 at 14:22
  • @Jason if i try to send it like above it never makes it to the server. the error comes from visual studio and server side never logs request was even tried. if i try to send it as a byte[] and not a json string it just comes up as undefined with no contents – theconfusedone2 Dec 04 '19 at 01:27
  • @Dijkstra if i log a request which i have done it comes up very log and the part containing the request just says its undefined. but as a string it never makes it – theconfusedone2 Dec 04 '19 at 01:30
  • @jason am i not supposed to send it as base 64 or byte is their a more efficient option thats shorter? – theconfusedone2 Dec 04 '19 at 01:31
  • a 414 "Request URI is too long" is a **server** error. Please post the **exact** exception message you are receiving – Jason Dec 04 '19 at 01:42
  • @Jason sorry for the slow response but heres the error System.UriFormatException Message=Invalid URI: The Uri string is too long. and i will add picture. i could be wrong it might be on the server but ussually it will give me an error on the server or at least do console.log('request tried') and on client side it will say something like internal server error – theconfusedone2 Dec 04 '19 at 03:32
  • I suspect refit is trying to urlencode your data and is barfing because of the size. – Jason Dec 04 '19 at 03:44
  • @Jason i am beginner tryna learn so am i trying to send it in a ridiculous format or something. cause i also tried base64 which is also long. this is my first time trying to send an image string rather then smaller strings and ints. any help info or implementations would be awesome. – theconfusedone2 Dec 04 '19 at 03:49
  • There’s no reason you can’t just send a byte[], but it really depends on what your server will accept – Jason Dec 04 '19 at 03:51
  • i sent a byte straight and getting this error clientside `Refit.ApiException: 'Response status code does not indicate success: 413 (Payload Too Large).'` and this serverside `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)` – theconfusedone2 Dec 04 '19 at 04:02
  • @Jason i will add new code – theconfusedone2 Dec 04 '19 at 04:03
  • @jason app.use(bodyParser.json({limit:'5000mb'})); app.use(bodyParser.urlencoded({limit:'5000mb',extended: true})); solved my problem – theconfusedone2 Dec 04 '19 at 05:45

2 Answers2

1

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

0

Try it! It work for me. Express v4 app.use(express.json({limit: '50mb'})); app.use(express.urlencoded({limit: '50mb'}));

Thiên Trần
  • 51
  • 1
  • 7