Sails 0.10 req.files empty on file upload - file-upload

I'm doing a file upload to sails v0.10 via
POST /file/upload HTTP/1.1
Host: localhost:1337
Cache-Control: no-cache
but the req.files object remains empty in sails
upload: function(req,res) {
console.log(req.files); // {}
}
in my file controller. What am I doing wrong?
Thanks!

One should know that since sails v0.10-rc6 the Skipper-middleware is automatically used, so if you're having the same issue, don't use 'req.files' anymore but use the req.file('name') function (https://github.com/balderdashy/skipper)

Related

Fetch with 'If-None-Match': "etag" header always returning 200 in React Native app

I'm encountering a very strange issue in a react native app where a simple fetch with an etag is always returning a 200 rather than an expected 304:
const response = await fetch(url, {
method: 'GET',
headers: {
'If-None-Match': etag
},
});
where etag is something like "33a64df551425fcc55e4d42a148795d9f25f89d4"
When I make this request directly through something like Postman/Insomnia, it is working and I get the appropriate 304 response.
Inspecting the app in Reactotron, I can see the network request header seems to be correct:
If I copy the JSON request as cURL I get the following:
curl -H "if-none-match:"33a64df551425fcc55e4d42a148795d9f25f89d4"" https://url/to/api
With a slight modification to show only the headers:
curl -sD - -o /dev/null -H "if-none-match:"33a64df551425fcc55e4d42a148795d9f25f89d4"" https://url/to/api
Which also only returns a 200, but if I escape the quotes around the etag like so, it works:
curl -sD - -o /dev/null -H "if-none-match:\"33a64df551425fcc55e4d42a148795d9f25f89d4\"" https://url/to/api
I'm genuinely confused because I've tried all variants of:
'If-None-Match': etag
'If-None-Match': `"${etag}"`
'If-None-Match': `\"${etag}\"`
'If-None-Match': '"' + etag + '"'
to no avail, what am I doing wrong?
Putting the same fetch request into an html file and testing in the browser works with the expected 304 status.
Under the hood, React Native is using NSURLCache which returns a 200 even when it receives a 304 from upstream, at least from what I’ve read online. Have a look using Charles Web Proxy or another such proxy from the App Store and you’ll see the traffic over the network before it hits your app. Googling reveals a lot of edge cases around caching also, such as apparently not caching private responses by default.
I'm getting the same issue using Axios on a React Native App. I also tried the opposite 'If-Match' and getting 200, so it's as if the header is not even there.
const query = {
method: 'GET',
url: `someurl`,
headers: {
Authorization: `Bearer ${token}`,
'If-Match': etag,
},
};
let response = await axios(query);

Vuejs Issue with the second request having 300ms overhead

I started learning Vuejs and I saw a strange behavior with the HTTP request to my web server. I'm using axios to make requests.
I just installed the vue-cli version 3.11 without using the webpack, and I added the config file vue.config.js next to package.json with the following content to proxy my web server
module.exports = {
devServer: {
port: 8081,
proxy: "http://127.0.0.1:8080"
}
};
Then using axios I'm trying to do a GET request by clicking a button
axios.get(API_URL, {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
"Cache-Control": "no-cache"
}
}).then(response => {});
My web server based on Python and bottle where the API request of fetching users takes between 5ms and 16ms to be processed.
By opening the browser inspector I saw that on the second request I'm getting an overhead around 300ms, please see below:
Request and Response parameters
Anyone has an opinion about this behavior? I searched a bit for vue-cli 3 issues or CORS headers but I did not find anything helpful. Thank you.

NodeRED http-response node: How to stop NodeRED adding charset to content-type?

I need to build a http proxy for a jpeg image inside NodeRED. My goal is that the browser does get all page resources in the dashboard from the NodeRED server. And the image is only available from another server.
I tried this abstract flow:
http-in -> http-request -> function node -> http response
In the function node I set the headers:
msg.headers = {
"content-type": "image/jpeg",
"content-disposition": "inline; filename=\"myimage.jpg\""
}
The problem is, that the browser gets these headers (excerpt):
content-type: image/jpeg; charset=utf-8
content-disposition: inline; filename="myimage.jpg"
Where the hell is charset=utf-8 coming from and how to stop NodeRED adding this?
You do not mention what msg.payload is set to in your flow.
If the msg.payload you pass to the HTTP Response node is a String, the content type gets the charset parameter added. This isn't deliberate behaviour of Node-RED - but something happening in the underlying http/express framework.
If msg.payload is a Buffer object, then no such parameter is added.
charset=utf-8, is added by node-red to define the standard there will be no issue if headers added charset on it.

Issue with set cookie headers from server and vue component vue-beautiful-chat

I have this issue on a Vue app, based on component vue-beautiful-chat: I make an http.post using http module via browser on localhost: when I check the response headers from the remote server, I see there are no "set-headers" with cookie values, only:
Content-Type application/json;charset=utf-8
If I send a post request via Node, Postman o cURL these are the response headers:
Connection keep-alive
Access-Control-Allow-Origin *
Set-Cookie JSESSIONID=wl6sCW6uT_9bAgoOSj9YtgfJvYGxF6XrNjH22YFm.srv79627; path=/
Server WildFly/10
Content-Type application/json;charset=utf-8
Content-Length 352
Date →Tue, 12 Mar 2019 22:33:25 GMT
In Vue app I receive
In the console developer I see in the tab application->cookies only one cookie saved on localhost.
Is this related to browser limitation? Any workaround?
I need to keep track of the value in set header from remote server for session management.
This is the actual code:
const options = {
hostname: 'XX.XX.XX',
port: 8080,
path: '/myurlsearch_2?searchText='+mess +'&user=&pwd=&ava=XXX',
method: 'POST',
rejectUnauthorized: false,
headers: {
'Cookie': this.$session.exists('JSESSIONID=') ? this.$session.get('JSESSIONID=') :''
// 'Access-Control-Allow-Credentials:true' -> this won't work
}
Thanks in advance

Graphql post body "Must provide query string."

I use Express-graphql middleware.
I send the following request in the body line:
POST /graphql HTTP/1.1
Host: local:8083
Content-Type: application/graphql
Cache-Control: no-cache
Postman-Token: d71a7ea9-5502-d5fe-2e36-0ae49c635a29
{
testing {
pass(id: 1) {
idn
}
}
}
and have error
{
"errors": [
{
"message": "Must provide query string."
}
]
}
in graphql i can send update in URL.
URL string is too short. i must send update model like
mutation {
update(id: 2, x1: "zazaza", x2: "zazaza", x3: "zazaza" ...(more more fields)...) {
idn
}
}
I think its must be in request body. How can I send 'update' query or that I'm doing wrong?
Post request needs to manage headers info.
Using Http client - Content-Type: application/json
Using Postman client - Content-Type: application/graphql
but request body looks like string
{"query":"mutation{update(id:1,x1:\"zazaz\",x2:\"zazaz\"......){id x1 x2}}"}
If you are using graphql and want to test it using postman or any other Rest client do this.
In postman, select POST method and enter your URL and set Content-Type as application/graphql then pass your query in the body.
Example:
http://localhost:8080/graphql
Mehtod: POST
Content-Type: application/graphql
Body:
query{
FindAllGames{
_id
title
company
price
year
url
}
}
Thats it you will get the response.
Using Postman Version 7.2.2 I had a similar issue. This version of Postman supports Graphql out of the box. Changing the Content-type to application/json fixed it for me.
for me worked like as following:
In the body
In the Headers
Don't forget mark GraphQl [x] on Body settings
And how was quoted before changes the verb to POST.
This generally occurs when your 'express-graphql' doest receive any params. You need to added a json/applicaton parser in your application.
npm install body-parser
eg -
const bodyParser = require('body-parser');
app.use(bodyParser.json()); // application/json
go to the relevant web page and open "inspect" (by write click ->
inspect || Ctrl+Shift+I in chrome)
go to the network tab and copy the cURL command
open the postman ,then import -> raw text
paste the copied command
then,continue ->
Switch content type to JSON.
Like this
Check if you are using correct protocol in your Postman requests.
I used HTTP instead of HTTPS and this caused the same error.
Changes of content-type, raw or json instead of graphql type didn't help.