• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Is it possible to upload file to drop-box with only file name(without path) using java?

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my web application i want to upload file to drop-box. I am getting file name from browser.Is it possible to upload file to drop-box with only file name.

Below the drop-box upload code with java.

File inputFile = new File("New Text Document.txt");
System.out.println("inputFile.getAbsoluteFile(): " + inputFile);
FileInputStream inputStream = new FileInputStream(inputFile);
try {
DbxEntry.File uploadedFile = client.uploadFile("/magnum-opus.txt",
DbxWriteMode.add(), inputFile.length(), inputStream);
System.out.println("Uploaded: " + uploadedFile.toString());
} finally {
inputStream.close();
}

In the above code the place New Text Document.txt we have to provide total path of file.

please help me.Thanq
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are you trying to achieve by that? DropBox is a file system, it makes sense that it needs a full path.

Or are you asking about the very first line of code which reads "inputFile"? If so, web apps have no concept of relative paths, you need to use absolute paths.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

kamesh vadam wrote:In my web application i want to upload file to drop-box. I am getting file name from browser.



Then that means that the HTML in the browser has an element which looks like <input type="file">, right? Your server cannot access that file using a Java File object, because the file in question is on a different computer. You need to do a file upload in your web application, which involves accepting the data which will be in the request. That data will be the contents of the file, which is what you want to upload to Dropbox anyway, isn't it?

I suggest Apache FileUpload to do that.
 
kamesh vadam
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK i am getting file if i give the same file name in above very first line it is showing file Not Found Exception.
so i should be store this file in temp folder in server right?
then i can give the path that file.like you mean that?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to make: the problemis not with uploading to DropBox, it is with upload a file to a servlet container? If so, check out the Apache FileUpload library Paul mentioned, it has a lot of documentation and examples on its web site.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're talking HTTP file upload, there are 2 schemes used by clients.

Internet Explorer passes the FULL client file pathname as part of the submit. This is actually not a good idea, since it tells the server things it doesn't need to know about your local filesystem

Most other clients only pass the filename itself.

To normalize the uploaded name (discarding the client's path), construct a java.io.File object from it, then use the getFilename() method to extract the simple filename without path.

Either way, do NOT store the uploaded data in your WAR. If you want the server to create local files from uploads, write those files to a directory that's external to both your webapp and the webapp server.
 
kamesh vadam
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what i have to exactly do......?
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to get an input stream to pass to DropBox.
File and FileInputStream are the wrong classes to use in this case. That is for Files already on the server.

You want the input stream from the file that has been uploaded to your servlet/jsp.
As already mentioned the Apache File Upload component will help you do this.


 
kamesh vadam
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So which classes i have to use.Please give me the information.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stefan Evans wrote:As already mentioned the Apache File Upload component will help you do this.


The underlined part is a link.
 
kamesh vadam
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i was used ServletFileUpload.But the probem is list size(items.size) is 0.But in request object i was getting file.where i have did wrong..?

my code is...


boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart) {
System.out.println("file is available");
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setRepository(new File(System.getProperty("java.io.tmpdir")));
System.out.println("file is available1" + factory.getRepository());
ServletFileUpload upload = new ServletFileUpload(factory);
System.out.println("file is available2" + upload.getSizeMax());
List<FileItem> items = upload.parseRequest(request);
System.out.println("file is available::::" + items.size());
Iterator<FileItem> iter = items.iterator();
while (iter.hasNext()) {
FileItem item = iter.next();
System.out.println(item.getName() + ":::::" + item.getFieldName());
}
System.out.println("file is available");
}
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't recall how that library works in detail, but make sure you're doing it like the user guide suggests.
 
Stefan Evans
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi i was used ServletFileUpload.But the probem is list size(items.size) is 0.But in request object i was getting file.where i have did wrong..?



Hooray for System.out.println. The best debugging tool known to man ;-)

How are you getting this code to run?
What gets printed out when you run this code?
What proof do you have the request object is getting a file? What tells you this? What tells US this beyond your assertion?
reply
    Bookmark Topic Watch Topic
  • New Topic