0

A related question was asked here move file uploaded from nanohttpd's Temporary directory to SD card

the reference questioner asks for copying an nanohttpd uploaded file to external sd card. However, if we wish to have a copy of the uploaded file inside the internal storage, how can we do it?(e.g. system assigned according to what device preference is sdcard or internal storage)

the author of the question did find a class method for making a copy of the uploaded file from the nanohttpd server (with a simple class method which copy from and to a particular directory) https://stackoverflow.com/a/4770586/1673000

however, how and where should we implement the codes? (with the proper approach in mind)

  • should we implement this code into the nanohttpd source file? (e.g. NanoHttpd.java) if so, how do we implement the code into the main class file.
  • are we able to keep the nanohttpd.java source file intact without modification and add this particular feature perhaps on another class file? (e.g. another class file which "extends NanoHTTPD" with some sample HTML code being parsed) or what are the recommended procedure in terms of having a clean design structure?

side note: I was hoping that I can copy the file directly after the nanohttpd operation are completed, but the temp file always gets deleted immediately after nanohttpd is turned off.

thanks for reading

Community
  • 1
  • 1
Bigs
  • 616
  • 2
  • 11
  • 17
  • As your app is turning nanohttpd off, your app could copy those files just before closing. Why not? I suppose that there will be three files if you do three uploads? – greenapps Aug 28 '14 at 22:35

1 Answers1

0

To move the uploaded file to internal/external storage, all you need to do is:

  1. Implements TempFileManagerFactory
  2. Implements TempFileManager
  3. Implements TempFile
  4. finally after creating server, call

server.setTempFileManagerFactory(new FileFactory());

  1. To get the filename of the uploaded file

Map files = new HashMap();

session.parseBody(files);

Log.d(TAG, files.toString());

  1. Then you can access the file
Nicholas Ng
  • 1,428
  • 18
  • 23