GraphiQL - upload file - graphql

How can we upload files using in-browser GraphQL IDE GraphiQL, is that even possible ? (apart from base64 encoded string)
Once I have the file stream / file contents I can create a mulipart request and store on DB or some object-storage service.
But I am not able to figure it out how to provide the file input / how the schema would look like. Is it better to use graphql-upload with Curl request. Please suggest which is the optimal solution.

I was able to upload a file in my mutation input using Altair. You can use the Add files button to upload a file, then use the upload name on your mutation.

Guys just try Altair, saved me a lot of trouble and time. It has extension for chrome too, just like Apollo playground or graphiql, but with file upload option underneath the variables option.

Currently GraphIQL does not support file uploads. You can use an API tool to do this such as Postman, Insomnia or plan old cURL. The important distinction is that it needs to be a multi-part form upload.
Example request:
curl --request POST \
--url http://localhost:4000/ \
--header 'accept: application/json' \
--header 'accept-encoding: gzip, deflate, br' \
--header 'connection: keep-alive' \
--header 'dnt: 1' \
--header 'origin: http://localhost:4000' \
--form 'operations={"query": "mutation UploadFile($file: Upload!) { uploadFile(file: $file)}", "variables": { "file": null } }' \
--form 'map={ "nFile": ["variables.file"] }' \
--form nFile=#/tmp/testfile
Substitute /tmp/testfile in the request above with a path to the file you want to upload.

Related

postman binary data-type detect and save in laravel request

In postman there is an option to send binary datatype in a api.
I am sending that in a api where but i am unable to detect that binary file in laravel request method.
curl --location --request POST 'http://192.168.*.*/api/v1/contact_us/save' \
--header 'Authorization: Bearer some_key' \
--header 'Content-Type: image/jpeg' \
--data-binary '#/Users/username/Desktop/filename.jpeg'
Above is my curl code generated in postman.
Although i am successfully getting this file when i request in multipart/form-data
I did see a question related to it but it is not the exact case
related question
If the HTTP request payload is purely a file (ie. not from a HTML form) then you can access it in Laravel using:
$request->getContent()

How do I send this multipart/form-data to a Web Service using Genexus?

The Following CUrl works perfectly whenever I test it:
curl --request PUT \
--url https://api.sandbox.URL_HERE/document-analysis/90471702021 \
--header 'Accept: application/json' \
--header 'Authorization: Bearer AUTH_TOKEN' \
--header 'Content-Type: multipart/form-data; boundary=---011000010111000001101001' \
--header 'api-version: 1.0' \
--form documentType=RG \
--form documentSide=FRONT \
--form 'image=data:image/jpeg;name=RG_Front.jpg;base64,/9j/4AAQSkZJRgABAQEAAQABAAD/4Tn0RXhpZgAATU0AKgAAAAgABgALAAIAAAAmAAAIYgESAAMAAAABAAEAAAExAAIAAAAmAAAIiAEyAAIAAAAUAAAIrodpAAQAAAABAAAIwuocAAcAAAgMAAAAVgAAEUYc6gAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA8JeLF8wysb6N95+837vqfyr2KvwCwP8VH2ABmkb5RQGx2qNm8zhTj3rk5rH0xImduKSY7UP0NPHFMlXcpHTrWiE9j8eNcuLbT/FWpXcipPi/uC1uyNIANzjHHBIyDjOOKyLW8eOS7gNrCTdRF7O3RiESOLUbZY4IdzF41TcQC2R87bm5bmv0mK4xg4HpSKvvUuTvoP6nT7n5yXf7KPxc1ZZVu/Blg6SzNM6HWwgJBCoC6PvYJGCqqWIGScE1auP2SPi/N5/k6PpzPNGgaS81OKRvMRsrIw2FXO0BeRkjqa/RPb6mk9s5p8zBYOmj88ZP2Q/i2bGZY9G0a3U5aOFdV3m2YjD+QzIfJDDIKgkYPGOtQ/8MY/F545IF0/w9DaTFQYDqLHZGH3MrfJ+8LHGWfeeOMV+ie31PNJt96lTfYr6pTPz7uv2Mfi1eNMGj8OqZFYSTSavcOZN3396mMpg4U4CjGwY4zmP/hhv4pLkJN4XXdsORqFwJBIo4lRxFuRupwDt55Br9BiWVckcD0py4ZfahzYfVKZ8FzfsY/FqaczjVPCkcwiMcbLL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was cut just to fit the comment field, but you get the idea.
I just have to send some info to the endpoint using HTTPClient but got stuck especially because Genexus says that the line is too big when I try to convert the image (1Mb) to a base64 string.
Has anyone gone through that?
It seems that the Web Service is expecting the new "multipart/form-data" instead of the old "application/x-www-form-urlencoded" for uploading files as explained here and the specification section for forms in HTML 4.01 is here. So, going to your question, I think that you can use the AddFile method of the HTTPClient data type (as explained here) to get your client working. Readink the wiki, it says:
In particular, if the content of the HttpClient message is multipart / form-data (given by Content-Type Header), then the AddFile method adds the file as multipart. In this case, the second parameter is needed to indicate the name of the variable that the file represents. Also, you have to necessarily precede your sentence with a header that specifies a specific Content-Type, like this:
&Httpclient.Addheader("Content-Type", !"multipart/form-data")
I say "I think" because I dindn't test myself, you can try and let us know if it works or not.

Google People API - get contact details (batch)

Using Google People API, one can get a contact detail by its ID.
"https://people.googleapis.com/v1/" + id + "?key=" + <KEY> + "&personFields=addresses,clientData,emailAddresses,names,organizations,phoneNumbers,birthdays",
Is it possible to get such details in batch? I have a list of 100 contact ids and I want them to get at once as it'd be much faster.
In your situation, how about using the method of "Method: people.getBatchGet"? When this method is used, the 200 resource names (maximum number) can be retrieved by one API call. When this is used for your situation, it becomes as follows.
Sample curl command:
curl \
'https://people.googleapis.com/v1/people:batchGet?personFields=addresses%2CclientData%2CemailAddresses%2Cnames%2Corganizations%2CphoneNumbers%2Cbirthdays&resourceNames=people%2Fsample1&resourceNames=people%2Fsample2&resourceNames=people%2Fsample3' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
In above case, the unencoded endpoint is https://people.googleapis.com/v1/people:batchGet?personFields=addresses,clientData,emailAddresses,names,organizations,phoneNumbers,birthdays&resourceNames=people/sample1&resourceNames=people/sample2&resourceNames=people/sample3.
Also, you can test this with "Try this API". Ref
Reference:
Method: people.getBatchGet

Error in Disable browser cache for a Cloud CDN's object (via Google Cloud Storage's bucket)

I have a bucket in Google Cloud Storage, and serving its content via Google Cloud Load Balancing having above bucket as backend. All the objects in the bucket are public. JS, CSS, HTML and images are stored in a bucket.
Since Cloud CDN doesn't support gzip compression (afaik) so I have uploaded gzipped files to bucket with appropriate headers.(All my users use browser which supports gzip compression)
I want to disable cache(specifically caching in user's browser, but no caching in Google's lb is also fine) for few js files. For that I have added below headers to the object in bucket
Content-Type application/javascript;charset=UTF-8
Content-Encoding gzip
Content-Language en
Cache-Control private, max-age=0, no-transform, no-cache, no-store, must-revalidate
Even after this browser is getting public cache headers with 1 year expiry. I tried sending same request via curl and below are the results.
curl -v --request GET \
--url https://cdn.intelliticks.com/prod/common/client/inject.min.js \
--header 'Accept: */*' \
--header 'Cache-Control: no-cache' \
--header 'Connection: keep-alive' \
--header 'Host: cdn.intelliticks.com'
returns correct caching headers. but below request(with accept-encoding header which is added by browsers by default)
curl -v --request GET \
--url https://cdn.intelliticks.com/prod/common/client/inject.min.js \
--header 'accept-encoding: gzip, deflate' \
--header 'Accept: */*' \
--header 'Cache-Control: no-cache' \
--header 'Connection: keep-alive' \
--header 'Host: cdn.intelliticks.com'
returns with 1 year caching. Any way to remove caching headers so that browser doesn't cache it?
Google Cloud CDN supports gzip if you put the correct header Content-Encoding: gzip when doing a request, however it is specified that objects should weight less than 10MB when specifying gzip encoding.
Regarding caching, there are some situations in which even if you specify no-cache, the content can be eligible for caching. For example, when using a signedURL the objects are then eligible to be cached.
Also objects are cacheable if they are publicly available, as it is your case. Maybe you can try to put the bucket as publicly readable and then specify the Cache-control header to each of the objects.
Also you can try changing your objects from public to private, therefore they are not eligible for being cacheable and then give access only to the range of users you wish.

Can Rasa chatbot initiate a conversation?

I'm planning to deploy the bot based on rasa with a monitoring engine. So if something goes wrong, I would like bot to start the conversation with a specific user. Is that possible?
An easy way to do so, would be to send a user message from your monitoring system to your input channel. So you basically mimic the user initiating the conversation. Note that I directly specify the intent using the / as prefix.
Start Rasa Core with the REST api exposed:
python -m rasa_core.run -d models --enable-api
Then you can send messages to it, e.g.:
curl --request POST \
--url http://localhost:5005/webhooks/rest/webhook \
--header 'content-type: application/json' \
--data '{
"sender": "<sender_id_of_your_user>",
"message": "/inform_about_failure"
}'
#Tobias's solution is the "old way" still valid to manage external events in a pull-based chatbot engine (not just RASA), when we want to push notifications to sender_id.
With the current RASA release, to run the RASA Core server the cli command is:
rasa run --debug --enable-api -m models
And the curl request #Tobias specified is still valid with current RASA version:
curl --request POST \
--url http://localhost:5005/webhooks/rest/webhook \
--header 'content-type: application/json' \
--data '{
"sender": "<sender_id_of_your_user>",
"message": "/inform_about_failure"
}'
On the other hand, the suggested way by RASA now (version 1.9.7), is to use external events management.
That way you can specify also the entities along with the intent to be triggered, as the example shows:
curl \
-H "Content-Type: application/json" \
-X POST \
-d '{"name": "EXTERNAL_dry_plant", "entities": {"plant": "Orchid"}}' \
http://localhost:5005/conversations/<sender_id_of_your_user>/trigger_intent
BTW in RASA, sender_id and conversation_id are different names for the same thing.
Definitely. But rasa_nlu got nothing to do with this, you will be sending a push_messagefrom your backend to the chat client from there rasa_nlu picks up the conversation.

Resources