GraphQl File transfer - graphql

Is it possible to transfer a picture from the back to the front as a Upload file? How to transfer file from back to front?
What I did to transfer the image from front to back:
Adding a new data type for a file:
Next, you will need to define scalar Upload in the sсhema.graphqls file:
The most important thing is not to forget to write the method in Mutations in the sсhema.graphqls file:
Look, I get javax.servlet.http.Part when I upload a photo. At the front we get the data through the Apollo hook useQuery/useMutation
But how do I send the photo back to the front?
After all, javax.servlet.http.Part is not transferred to the front?
How to write a method signature in the sсhema.graphqls file in Query section and in the implementation of this method in GraphQLMutationResolver implemented class?
I need to transfer the file. If the GraphQl team sees this message, please write more documentation on this topic.

Related

Kademi - allow front end user to delete a file they have uploaded

I am trying to allow front end user to delete a file they have uploaded.
#docs() tells me that $page.lead.files has a method called .remove() that accepts either an Int or an Object.
I keep getting a response of "false" when using this method. I am trying to pass and ID or Object of a file within $page.lead.files object.
Debugging...
User: https://spinsurance.admin.kademi.com.au/manageUsers/116783806/#summary-tab
Page: https://crm.spinsurance.co.nz/leads/148615383/
Source: https://spinsurance.admin.kademi.com.au/repositories/spcrm/version1/theme/apps/leadman/components/texteditor?fileName=leadDetailTabContentComponent.html
Under section on page called: Uploaded Files.
Click big red Delete button. (I don't mind if this file gets deleted)
Thanks for your help in advance.
The Lead.files property is a persisted list. Its not a good idea to try to modify the database using that approach.
Note that lead files are exposed as http addressable resources, which support the http DELETE method
So the simplest approach is to delete from the browser using ajax
Eg
DELETE /leads/123/myfile.pdf

Add content disposition param for uploadTask using URLSession and URLRequest

I am using URLSession 'uploadTask from file'
func uploadTask(with request: URLRequest, fromFile fileURL: URL) -> URLSessionUploadTask
Almost everything works fine, but now our server needs an extra param as 'uploadKey' to be passed as content disposition along with fileName.
This can be done by generating multipart request with content disposition added as we normally do.
I want to add it while using 'uploadTask from file' to avoid memory pressure. Please suggest how to do it.
From reading the question, I suspect that you're subtly misunderstanding what upload tasks do (and unfortunately, Apple's documentation needs some serious improvement in this area, which doesn't help matters). These tasks don't upload a file in the same way that a web browser would if you chose a file in an upload form. Rather, they use the file as the body of an upload request. I think they default to providing a sane Content-Type based on the filename, though I'm not certain, but they do not send data in form encoding.
So assuming I'm fully understanding the question, your options are either:
Keep using multipart encoding. Optionally write the multipart body into a file rather than keeping it in memory, and use the upload task to provide the body from that file instead of from an NSData object.
Upload the file you're trying to send, unencoded, as the entirety of the upload body, and provide whatever additional parameters you need to provide in the form of GET parameters in the URL itself.
Use some other encoding like JSON or protocol buffers.
Either way, the server code will determine which of these approaches is supported. If you can modify the server code, then I would recommend the second approach. It is slightly more efficient than the first approach, much more efficient than JSON, and easier to implement than any of the other approaches.

Firebase functions callable - image as argument

I have a firebase function which given some arguments creates a "post" with a title and the such. Is there a way to send an image as an argument which can then be processed by firebase functions and then upload to firebase storage.
I think it is possible by decoding the file/image object to a base64 string which could be then sent as an argument. How would I convert the file object from html file input to base64? On the other side how would firebase functions know that the string is an actual image? How can I tell the size of the image? Is there a limit to the size of arguments given to a firebase callable function?
I ditched this question but came across the problem later in a different project. So to anyone seeing it is possible through base 64 strings. It has the restraints that the image cannot be bigger than 10mb but it is easier than trying to "catch" the file after it being uploaded directly.
Here is the solution
I would do the following:
Let the user upload the file directly into firebase storage in a folder where only the user has access to.
Let a function trigger on upload that takes this image, checks if the user is authorized to put that in the target folder and put the file in there (or whatever you want the function to do exactly).

Web service exposing images : ddl or base64?

My question is quite simple but I can't find any clear reference : I'm building a webservice that returns gameboard informations (in json for unity) and the image of the game.
Should I, in my informations include a field "image" with my image in base64 ?
Or in my information include a field "image" with the exposed url of the image (on my server still), and then do a second call to get the image ?
Which is the best practice toward unity android/ios ?
OK, i will prefer to use first option.Your information include image field.As http works with TCP it will deliver 100% and i think there is no need for second call to get game image
In my experience, use the second method avoid downloading the same image every time when I call the webservice.
I just check the image if exist in persistent data directory of my device. Don't need to download the resource again until the url content changed.

JSP to insert image into DB, display it to client

I want to insert an image to database and display it in another page. I am using the PostgreSQL database.
My guide suggests that I insert the image with its file path in the database. When displaying, in place of the src attrib of img tag put the path from database. So can I get any help for this .
Please guide me for this or give me link for similar kind of problem.
(I'm a final year student, and feel that this project requirement is difficult).
Your guide is entirely correct. Part of what you are supposed to be learning is problem solving: how to break a big problem down into many smaller, simpler problems you can solve piece by piece. It sounds like it's hinting at this, but expects you to be able to do that yourself, which is pretty reasonable.
You need to break this down into steps, and do each step in isolation. That's how anything but the most trivial programming task must be done.
(It isn't clear if you want to store the image data in the DB, or just a file system path, by the way, so I'm assuming you want to write the file to the local file system and just store the path in the DB).
Anyway, this should be fairly simple JSP. To display:
One JSP that:
Examines the query parameters for the image ID
Uses JDBC to fetch the associated path of the image on the file system from the database (a simple SELECT using the image ID as a query parameter)
Opens the image on the file system as a binary stream; also stats it to get its size
Sends appropriate HTTP headers eg Content-Type: image/jpeg and Content-Length: image-length-in-bytes to the client
Copies the raw image data from the image input stream to the output stream that sends to the client
Another JSP that generates the HTML and has an <img src="/the/image/jsp?imageid=blah"> link in it.
If you're required to submit just one JSP file, you can combine the two by having the JSP show a HTML page if it doesn't receive any query parameters, and send an image if it does receive an image id as a query parameter.
To insert:
One JSP that displays a HTML form with a file upload link if it doesn't get called with any HTTP POST data
If the JSP does get called with HTTP POST data:
** Issue a JDBC INSERT to create a record for the file in the database, but do not commit
** Access and decode the POST data using the methods provided in JSP
** Extract the desired file name from the form data and open a binary output stream to a file on the filesystem with that name
** Copy the image bytes into that output stream, url-decoding if required (the HTTP POST form handling code in JSP is likely to decode it to a byte stream for you, though)
** Flush and close the output stream
** Commit the transaction with the JDBC INSERT.
You should be able to find numerous examples of both with a quick Google search. If you can't, adapting examples from other programming languages should be easy enough.
For inserting you must think carefully about the error cases. That's a large part of proper programming.
I am intentionally not showing you code examples. You should be able to do this yourself if you're a final year student. You won't know everything you need, but by now you should know how to find out what you don't know when you need to know it. Tutorials. Documentation. Google. Writing test programs to figure things out. Method name autocomplete in NetBeans / Eclipse. Adapting sample code. You've got lots of options.

Resources