Say I have an image file that is located in http://a.com/example.jpg
Then I have a network storage called http://b.com/
Using java, how can I move example.jpg directly to b.com?(Kind of like P2P??)
EDIT
I think I should explain a little bit more.
I want to move file example.jpg to b.com without downloading the file.
Normal approach will be
Open connection to a.com
Download example.jpg to my computer (either memory or disk)
Open a new connection to b.com
Upload the example.jpg to b.com
However, I think this involves unnecessary work.
What I want is this
Open connection to b.com
Without opening connection to a.com, upload example.jpg directly to b.com (I think this is the part where I thought of P2P)
Is there any way that I can do this?
There is no general way to do what you ask merely with HTTP. You would have to have specific support for such operations on the server hosting your network storage, such that you can request it to download URLs directly.
You can get the image using HttpClient from a.com and then upload it to b.com. How do you upload it b.com depends on what you have there.
To be able to do this without downloading the file you will need specific support on b.com. That specific support will be a service on b.com where you send a "download" request and the server will download the file itself from a.com.
Related
I have an android application, which wants the user to login each time he runs the app. So, the login procedure is simple, using the sqlite dabase file i'm using. I've copied the file in assets folder and doing the necessary modifications. But, the database file is of no use unless it is on the server. I don't have any server so i'm thinkin of keeping the database file on dropbox, google drive etc and then read or update that file as per user commands. The question is how to do that? I was searching the web for it, and found that the only way is downloading the db file modifying it and the uploading it back. Can anyone give me an example??
Doing that isn't possible unless you have a server.
Because, if you are using dropbox, first you'll have to make your file public in order to download it (Not recommended at all. Compromises security). Then you can use the url to download the file. But you won't be able to upload it back (Unless you are able to login to dropbox through your Android code).
Instead if you a web server with MySQL n PHP, you can easily send POST requests to your server.
In my webapp users can download the files among themselves. If a user A has shared a file F , then user B after connecting to A can download the file F from A. Till now each user makes a simple HTTP connection like :xxx.xxx.xxx.xxx/FileList with another user. The file resides on the local hard disk of each user. So that a user can download a file there were two options in my mind.
As the user shares a file,copy that file into the web-app directory of the server,so that the download link becomes as simple as Click to download.
Run a separate FTP server on each node.
I don't know which one of these is a better option but the first one seems very simple to me. What are the ways each client can share the files,without having to copy the stuff somewhere in the webapp directory. How in this case I can use a P2P protocol ?
NOTE : I am using Tomcat 7.
Real P2P is impossible without opening a listening socket on the client machine (that imposes you have to install something on client machine).
If you don't want to STORE the files on the server, I would rather recommend a "connection server", which serves as a gateway between the two users. User A will upload, user B will download at the same time, all you need is to make the bytebuffer in memory. The downloaded bytes can be dropped.
You can write a small client-side program in any language for updating the available files, and receiving the upload request from the server side (also execute the upload)
I would recommend using TCP sockets for upload to the server side, this way you have direct control over the uploaded bytes (streams).
There are some interesting technical issues here (blocking streams, metadata (filename, length, createdate, ...), data consistency, error handling, etc.) that should be taken into consideration. Nice task.
I don't recommend FTP because you cannot control the authentication and authorisation (who can see the files).
What would be a scalable file upload/download system/database?
I'm building a website where users can login, upload images that are private, but truly private. I can't upload them to a map on the harddisk of a server, since that would not scale (what happend if we add more servers?) and it wouldn't be private since everyone could go:
http://127.372.171.33/images/private_picture.png
and download the file.
I am building the project in Play Framework (scala/java)
How do websites like flickr handle these kind of things? Do they put them in a database? And what kind of database would be suitable for this situation?
Thanks for help
I can't tell you how those big sites handle it but putting those images into a database might be one way.
Another way would be to put the files into a virtual filesystem that spans a cluster of servers or distribute them onto different servers and just don't make the directories that contain the images visible to the webserver. Thus nobody should be able to open the image just using the server and the path on that server.
To actually deliver the images you could them implement some streaming service that sends a bytestream to the browser for display (like the webservers would do as well). This service could first check the download permissions for the requested image.
I have been messing around with GWT uploads lately. I want to have the ability to upload an XML file from the client, and get the contents of that file (display the contents in a TextArea).
From what I have found on the net, it seems I would have to upload the file to the server, and then get the contents of the file. I do not particularly like the idea of allowing file uploads to the server (even if they are only XML). Is there anyway to pull the contents of a file that the client specifies without sending it to the server?
Thanks
Recent (decent?) browsers implement the "HTML5" File API that's quite easy to use in GWT using JSNI.
See also: https://developer.mozilla.org/en/Using_files_from_web_applications
Because of security restrictions you cannot access the file on the client side alone. It has to be sent to the server for processing.
We have a web application that allows user to download a zip file from a web server. We just provide dummy iframe source to the full URL of zip file on web server. This approach would allow end user to use browser controls which allows the user to open or save the zip to user's local machine.
We have a requirement that the zip file is automatically extracted and save to a specific location on user's machine. Any thoughts on how this can be achieved?
Thanks.
I highly doubt that you'll be able to do that. The closest you're likely to get is to generate a self-extracting executable file (which would be OS-dependent, of course).
I certainly wouldn't want a zip file to be automatically extracted - and I wouldn't want my browser to be able to force that decision upon me.
Short answer is I don't believe this is possible using the simple URL link you've implemented.
Fundamentally the problem you have is that you have no control over what the user does on their end, since you've ceded control to the browser.
If you do want to do this, then you'll need some client-side code that downloads the zipfile and unzips it.
I suspect Java is the way to go for this - Javascript and Flash both have problems writing files to the local drive. Of course if you want to be Windows only then a COM object could work.
Instead of sending a zip file why don't u instruct the web server to compress all the web traffic and just send the files directly?
See http://articles.sitepoint.com/article/web-output-mod_gzip-apache# for example.