It seems the service its returning 400 and Error when parsing request output when the files are kinda big (Well not at all, because i'm trying to upload a 505kb .zip and its returning me an error), any kind of solution about this? Seems to be a random stuff because i upload a .pdf with a size of lets say 244KB and it returns error and then i try to upload a pdf with a size of 300kb and it goes fine, seems the CDN endpoint is having a strange behaviour, its also me happening with the images but not with the same frequency as the files.
Anyone have any kind of fix for this or idea why its happening?
I tried used postman and nodejs code and the results are always the same
try {
const response = await channel.sendFile(fs.createReadStream('file.pdf'),'file.pdf');
console.log(response);
} catch(e) {
console.log(e)
}
}
The process is returning the following
{ FetchError: invalid json response body at https://chat-us-east-1.stream-io-api.com/channels/messaging/XXXXXXX/file?api_key=XXXXXX reason: Unexpected token E in JSON at position 0
at /Users/user/Desktop/react-stream-chat-nodejs/node_modules/node-fetch/lib/index.js:272:32
at process._tickCallback (internal/process/next_tick.js:68:7)
message:
'invalid json response body at https://chat-us-east-1.stream-io-api.com/channels/messaging/XXXXXX/file?api_key=XXXXXX reason: Unexpected token E in JSON at position 0',
type: 'invalid-json' }
Related
I'm using react query to do a POST request. The request is successful the first time it executes, but keeps producing this error afterwards, even if the page refreshes. It also works if I clear cookies, but only once then the error keeps coming. This is the error message :
SyntaxError: "[object Object]" is not valid JSON
at JSON.parse (<anonymous>)
at AxiosClient.js:22:1
at async loginUser (user.api.js:7:1)
at async Mutation.execute (mutation.ts:200:1)
I have confirmed that in fact my POST body is not empty or undefined.
It sounds like your POST request is returning an object instead of JSON, which is causing the error. Try parsing the response from your POST request before returning it to the caller.
I am using the GMail API to retrieve messages. The messages are machine generated, so follow a similar format.
Although most of the messages are fine, I am getting a DOMException using atob to decode the message body for a subset of the messages.
I think I've narrowed it down to messages that have a section in it that looks like:
--------------------- Sudo (secure-log) Begin ------------------------
jeremy => root
--------------
/usr/bin/docker - 5 Time(s).
---------------------- Sudo (secure-log) End -------------------------
Specifically I think that the problem happens because of the =>.
The error is:
Error parsing DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
Code fragment:
gapi.client.gmail.users.threads.get({
userId: 'me',
id: thread.id
})
.then(function(response){
var
content,
message = response.result.messages[0],
rawContent = message.payload.body.data;
try{
content = atob(rawContent);
}
This thread helped me Decode URL Safe Base64 in JavaScript (browser side)
rawContent = rawContent.replace(/_/g, '/').replace(/-/g, '+');
Fixed it up.
How can I catch an HTTP 404 error using the Terse REST API in CodenameOne? At the moment the default error handler gets this but I would like to display my own message instead. The code I am using is fine if the accountNo exists and I can deal with the resulting JSON, but if not I get the standard error handler displaying the 404 error:
Response<Map> jsonData = Rest.get( URL + "lookup").
jsonContent().
queryParam("account",accountNo).
getAsJsonMap();
This seems to be a mistake in that version of the method. It should fail silently without a UI Dialog. We'll fix it for the next update.
Notice that jsonData should have the error response code within it as jsonData.getResponseCode().
I'm trying to POST a file as a base64 string to my API from a react app using axios. Whenever the file seems to exceed a certain (small ~150ko) size, the request is not sent and axios/xhr throws a Network error:
Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:87)
Any ideas?
It seems that basic POST requests using axios are capped in there file size. Using multipart form data for those uploads (populating a form with my file) seems to solve the pb
Source
But ultimately we moved to uploading directly to our AWS/S3 using a signed uri provided by our backend.
The problem is your type: of your file might not be valid one as per the MIME type. please check in your console
There might also be the problem of repeating the baseURL which means NETWORK_ERROR 404 NOT FOUND like of.. so please see the example below
let formData = new FormData();
formData.append("files", {
uri: payload.uri,
name: payload.name,
type: `payload.type?payload.type:image/${fileExt}` //this should be a valid Mime type
});
axios.post(`v2/upload_comment_file`, formData, {
headers: {
...(await HeaderData()),
"Content-Type": "multipart/form-data",
},
});
find mime type might get lil tricky for some image and doc picker lib like expo-doc-picker in ver 35.. please try react-native-mime-types https://www.npmjs.com/package/react-native-mime-types which helped me out and can help you too
The code I am using is:
var frisby = require('frisby');
frisby.create('Get paf data')
.get('https://services.....')
.expectStatus(200)
.expectHeaderContains('content-type', 'application/json')
.toss();
The error I get while running it from CLI using
jasmine-node EndpointTest_spec.js
The error I get is:
Error: Expected 500 to equal 200
Error: Header 'content-type' not present in HTTP response
So do I need to first load my website and call services through my application and then run frisby ?
But then it defeats the purpose of just making a quick check for all the endpoints used in application without running it.
You are calling request with https:// which may be secure server so use
{ strictSSL: false} in your get method .get('https://services.....',{ strictSSL: false}). It will solve your problem.
var frisby = require('frisby');
frisby.create('Get paf data')
.get('https://services.....',{ strictSSL: false})
.expectStatus(200)
.expectHeaderContains('content-type', 'application/json')
.toss();