I'm trying to implement file download directly via Browser. Our company uses Protocol Buffer as data communication format. So how can I download the file once I open the web page?
I tried to user bytes and stream of Protocol Buffer. But the result is
{"result":{"data":"Cw4ODg4ODgsMCw4ODg4ODgsMTUwMCwwLDE1MDAsNDAwMDAsMTAwMDAsMzAwMDAKMDMvMTEvMjAxNSxVbmtub3duIEl0ZW0sUHJlIFJvbGwgVmlkZW8gKG1heCAwOjMwKSw2MDAwMCwzMTAwMCwyOTAwMCw1MDAwMCwyNDAwMCwyNjAwMCwyMC4wMCUsODQ0NCwwLDQwMDAsNDQ0NCw4OTAzODgsMCwwLDAsODg4ODg4LDAsODg4ODg4LDE1MDAsMCwxNTAwLDQwMDAwLDIxMDAwLDE5MDAwCg=="}}
Protobuf is good for structured communication but http provides the perfect protocol for downloading files. The right headers need to be set and the browser will download the file.
If you really have to use protobuf to transfer files, then you need to add some javascript that is parsing the protobuf first and then turns it into a file that can be downloaded. See How to create a dynamic file + link for download in Javascript? for reference.
So, send the message as bytes, add the javascript that parses the protobuf message to extract the bytes, and then create the file download like on the linked answer.
Related
I'm the company's file server
Get the file as byte[] through the image path and authentication key.
(This server is not accessible to me.)
What I want to do is, when the user downloads the selected files, I want to compress these files and provide them as a compressed file.
Since the company's file server does not have a download API for multiple files, I think I need to request as many APIs as the number of file lists with a for statement in my service API.
In other words, it seems that we need to take a List<Byte[]> and compress this list.
Is there something wrong with my method?
And can I pass the result as json after compression? (I confirmed that the image file is passed as json.)
I am writing a Bittorrent client in Go and I would like to save the progress of the download by writing a bitfield to the file headers/metadata. This allows me to cancel the download and restart from where I left off the next time I start downloading.
However, I could not find any standard or third party libraries that allow me to write to file metadata. The closest I have gotten was printing the FileInfo struct returned by os.Stat. I am not sure how to add/edit the FileInfo struct.
I realized there are no library functions in Golang like that because metadata is a filesystem specific implementation. So, I have decided to hide my metadata in a hidden file like .filename.meta
Our application is entirely built on websockets. We don't do any HTTP request-reply. However, we are stuck with file download. If i receive file content via websockets can I wrote to local folder on user computer ?
If it makes a difference, we are only supporting Chrome so not issue if it doesn't work on other browsers.
Also, I know i can do this via HTTP. Trying to avoid it and stick to websockets since thats how the entire app is.
Thanks a lot in advance!
The solution depends on size of your file.
If size is less than about 50 MB, I would encode file's content to base64 string on the server and send this string to the client. Client should receive parts of the string, concat them to single result, and store. After receiving whole string, add link (tag <a>) to your page with attribute href set to "data:<data_type>;base64,<base64_encoded_file_content>". <data_type> is a mime type of your file, for example "text/html" or "image/png". Suggest file name by adding download attribute set to name of file (doesn't work for Chrome on OS X).
Unfortunately I have no solution for large files. Currently there is only FileEntry API that allows to write files with JS, but according to documentation it is supported only by Chrome v13+, learn more here https://developer.mozilla.org/en-US/docs/Web/API/FileEntry.
So I'm pretty new at all this. I am trying to reverse engineer a web application.
When I submit a form, it sends a POST with a request payload that looks something similar to this:
encoding=UTF8&zip=1&size=136240&html=DwQgIg_a_whole_lot_more_gibberish_not_worth_posting
Anyways, from inspecting the captured traffic from Chrome developer tools, I noticed it is encoded and sent as a zipped up html?
How would I go about reversing this to see what the content is actually being sent to the server?
What you want to do is this:
1) Get the name of the zip file
2) Get the path of the zip file (likely the root directory or the current path the form is at)
3) Generate the URL (http://site_name.com/path/to/folder/zip_file.zip)
4) Download it using a too such as wget (typing the URL into the browser may work too)
I used this technique to download all the files that get downloaded to the OTA updates on iOS devices (used burp suit to intercept the zip file name where the server was on my computer which my iDevice was connected to).
Please note: the name of the zip file you have given does not end in .zip. this may mean it doesn't have a extension; you may have to add .zip to the file manually; or it may have another ending such as .tar, .tar.gz etc.
After this line:
String photoFileLocation = Capture.capturePhoto();
I want to transmit such image to a server. How Can I get the bytes[] of the file which name is in the variable 'photoFileLocation'?
Use FileSystemStorage to open files.
But for actual file upload you should use MultipartRequest which accepts file URL's (more efficient than reading bytes). You can see an example of this including the server code in the recent workshop we released https://www.codenameone.com/blog/build-mobile-ios-apps-in-java-using-codename-one-on-youtube.html
You can see a full sample in the JavaDoc for multipart request here: https://www.codenameone.com/javadoc/com/codename1/io/MultipartRequest.html