Expo Dev Server - 'Payload Too large' Error - react-native

I have a redux driven app that’s been working great. But I recently got an error when I tried to read some properties from a state object in my jsx. The state object only has ~30 fields, not big at all.
Here's the error:
PayloadTooLargeError: request entity too large
at readStream (/Users/a/.nvm/versions/node/v16.14.2/lib/node_modules/expo-cli/node_modules/raw-body/index.js:155:17)
at getRawBody (/Users/a/.nvm/versions/node/v16.14.2/lib/node_modules/expo-cli/node_modules/raw-body/index.js:108:12)
at read (/Users/a/.nvm/versions/node/v16.14.2/lib/node_modules/expo-cli/node_modules/body-parser/lib/read.js:77:3)
at jsonParser (/Users/a/.nvm/versions/node/v16.14.2/lib/node_modules/expo-cli/node_modules/body-parser/lib/types/json.js:135:5)
at call (/Users/a/.nvm/versions/node/v16.14.2/lib/node_modules/expo-cli/node_modules/connect/index.js:239:7)
at next (/Users/a/.nvm/versions/node/v16.14.2/lib/node_modules/expo-cli/node_modules/connect/index.js:183:5)
at remoteDevtoolsCorsMiddleware (/Users/a/.nvm/versions/node/v16.14.2/lib/node_modules/expo-cli/node_modules/#expo/dev-server/src/middleware/remoteDevtoolsCorsMiddleware.ts:31:3)
at call (/Users/a/.nvm/versions/node/v16.14.2/lib/node_modules/expo-cli/node_modules/connect/index.js:239:7)
at next (/Users/a/.nvm/versions/node/v16.14.2/lib/node_modules/expo-cli/node_modules/connect/index.js:183:5)
at serveStatic (/Users/a/.nvm/versions/node/v16.14.2/lib/node_modules/expo-cli/node_modules/serve-static/index.js:75:16)
From what I saw on stack overflow, this error is associated with json size limits in the body-parser node module… and as I can see from my error, body-parser is used by the connect node module which acts as expo’s HTTP server.
Related stackoverflow questions all seem to be for express.js (like this one node.js - Getting error PayloadTooLargeError: request entity too large in case of Using express.Router() Post call - Stack Overflow).
What’s causing this in expo? Is it indeed body-parser?
How I can increase the json limits in an expo app like others are doing in express?

Related

Why is my apollo-server-express instance hanging due to resolvers?

I've recently wanted to get back into programming, and I know that Apollo GraphQL has moved to an asynchronous way to firing up the server per their documentation.
Since switching (and following docs), I can't get my server to fire up, and I don't know why.
When the server attempts to run, it hangs on the execution of .start() on my ApolloServer instance, even though I'm giving it (what I think) are both valid type definitions and resolvers.
The current iteration of my tiny boilerplate project is located here on CodeSandbox.
When I run this code locally, I receive the following error (which isn't shown on CS?):
Argument type {typeDefs: DocumentNode, resolvers: {Query: {hello(): string}}} is not assignable to parameter type ApolloServerExpressConfig
This error is on line 9, where the instance of ApolloServer is created.
I don't know what I'm doing wrong. I was previously using babel-plugin-import-graphql but switched away from that to using a normal JS import w/ the gql tag just to be safe. The problem appears to be with the resolver map, which doesn't make sense:
const resolvers = {
Query: {
hello: () => "world!"
}
};
export default resolvers;
Anyway, thanks in advance! Would love to get this sorted out today. I think if I don't, I'll end up just switching over to using Meteor for full-stack stuff and then use React for the front-end and just not worry about it anymore.

Increasing body limit size in apollo-server-express

I am trying to upload files to a webservice using the Upload scalar in apollo-server-express. I can upload small files(10s of kbs) to the webservice but am having trouble getting larger files to send.
I did some searching and found that I can change the body size limit using the body-parser package, along with the bodyParserConfig option set in middleware. I've tried implementing this, as well as implementing it in the express app itself, however neither seem to be working.
bodyParserConfig example snippet
const bodyParserConfig = bodyParser.urlencoded({limit: '50mb', extended: 'true', parameterLimit: 10000});
server.applyMiddleware({ app, path: process.env.GRAPHQL_ENDPOINT, bodyParserConfig});
I'm not sure if I need to use the json method as inside the apollo service it calls json(config) so I tried this and it also didnt work.
const bodyParserConfig = {limit: '50mb'};
server.applyMiddleware({ app, path: process.env.GRAPHQL_ENDPOINT, bodyParserConfig});
express example snippit
app.use(bodyParser.json({limit: '50mb'}))
Trying out both of these options, as well as options from Error: request entity too large don't seem to work for me. The webservice(Nifi HTTPHandleRequest) tells me it failed to receive content. Most examples of solutions(like the one above) have been specifically for express and not apollo-express-server so I'm not sure if theres a different approach I need to take. The apollo-server documents state to use the bodyParserConfig option, so I'm wondering if I'm not formatting the config correctly.
Is there something simple I'm doing incorrectly? Also how can I view what the limit is? It's hard to debug and see if the options I'm setting are actually doing anything.
Thanks
I guess the first step in debugging is figuring out whether te faillure occurs on sending or receiving.
Can you send this message to a different kind of webservice?
Can you receive this message from a different tool into NiFi?
You don't mention how large the messages are, but it seems that in sending you try to set the limit to 50MB.
I don't think this is a problem for NiFi in general, but if you are specifically using multipart/form-data the default limit is set to 1MB.
This could be adjusted via the setting: Multipart Request Max Size

Can React-Native [TypeError: Network request failed] mean internet connection failure or RN fetch timeout?

Sorry I've gone through every stack overflow question of this exact same error and no one has definitely provided an answer to this.
My production app only sometimes gives this error per my reporting service, so I am thinking two things:
Internet connection blipped out which it often does
There's some React Native timeout or under the hood machinery that cancels the attempt if the server hasn't returned anything.
To clarify:
fetch().then((response) => {
// Server returned something, even 500
}).catch((e) => {
// Server returned nothing OR internet connection bad?
// RN doesn't care to share why, just "I couldn't fetch"
});
since the fetch function is a javascript function, let's see what MDN docs say :
A fetch() promise will reject with a TypeError when a network error is encountered or CORS is misconfigured on the server side, although this usually means permission issues or similar — a 404 does not constitute a network error, for example.

Webap, Unable to read the entity body in Bufferless mode. The request stream has already been buffered

I am trying to do a fileupload in the webapi and having issues.
The execution is getting failed at this line:
var result = await Request.Content.ReadAsMultipartAsync(streamProvider).ContinueWith<HttpResponseMessage>(t => {..})
Hence I kept a code to see even if the content is rendered at the top of the above code as:
Request.Content.ReadAsStringAsync().Result
Now the error says.
"Unable to read the entity body in Bufferless mode. The request stream
has already been buffered."
Finally I have resolved this issue.
For some reason the framework wasn't liking the below code in WebAPIConfig.cs
config.Services.Replace(typeof(IHostBufferPolicySelector), new WebHostBufferPolicySelector());
I have commented this line and my code started working.
The only change I have seen is I have upgraded my .net framework to 4.6.1 and I think we no longer need this configuration for the newer frameworks.

Remote server returned an unexpected response :(417) Expectation Failed: Using MS Translator API in Windows Store App

I am trying sample code of Microsoft Translator in Windows Store App from this link
The sample code is given here
When I run the app, I get an exception "The remote server returned an unexpected response :(417) Expectation Failed"
This exception occurs on the following line:
germanTranslationTextBlock.Text = await webService.TranslateAsync("Bearer " + accessToken.access_token, sourceTextBox.Text, "en", "de", "text/plain", "");
P.S. I am behind a proxy.
Some googling shows that System.Net.ServicePointManager.Expect100Continue = false; is the solution but I do not know how to do that for Windows Store App.
Could not solve this error, but got a better and infact best source code [which works successfully] for doing text to speech and translate too here.
Could have saved a lifetime if I would have found it earlier, but it's really hard to find any good resources for windows app development.