0

I'm currently working on an Android app where app takes some pictures

My requirement is to save those pictures at Local storage first, then app uploads pictures API(its an app requirement). As soon as pictures are uploaded to API i need to delete pictures from local.

I don't understand where to start,

  • First I thought to use firebase, since it might cost i'm backing off.
  • Use DB to store path of an image in media, but it hard to delete the image from the app(I tried)
  • Internal file storage system, I think it is very slow

Note: pictures cannot be compressed. Any suggestions sample code/ any new idea is really appreciated

Update storing in file system, actually works.

Akhila
  • 3,235
  • 1
  • 14
  • 30
  • `...successfully uploaded to API "these" need to be deleted` , what do you mean by these? – Shashank Mishra Aug 10 '18 at 15:20
  • I don't know why do you think that but Local Storage is definitely faster and more reliable compared to storing it to any server. – Shashank Mishra Aug 10 '18 at 15:23
  • Try this [link](https://www.androidauthority.com/how-to-store-data-locally-in-android-app-717190/) for local storage tutorial – Shashank Mishra Aug 10 '18 at 15:25
  • These means> The uploaded files need to be deleted. when the network is onPostExecute > delete the pictures which are uploaded... – Akhila Aug 10 '18 at 15:39
  • Which local store do I need to use, can you please suggest me? Internal/ extrenal/ DB/ shared preferences. I tried with DB, It was very hard to delete the images from google photos. Internal storage /External storage i have tried but no idea how to use them for pictures, I did stored them by files but retrieval back is taking time. If you can provide me the source code of usage i would test the time taken and will be able to judge based on it. Thank you – Akhila Aug 10 '18 at 16:21
  • Try this [thread](https://stackoverflow.com/questions/17674634/saving-and-reading-bitmaps-images-from-internal-memory-in-android) for how can you store image to local storage and retrieve it. – Shashank Mishra Aug 11 '18 at 08:45

2 Answers2

1

I don't understand why the internal file storage is slow just save it to:

Context.getFilesDir().getAbsolutePath() + "/" + [filename]

Then you can create a file object from that path and delete it by writing:

Files.deleteIfExists(path)
Epig
  • 70
  • 9
  • Can you please provide me a source code where i can check the usage ? I really don't understand by the bits of code, I would really appreciate your help. – Akhila Aug 10 '18 at 15:42
  • I think i wasn't clear enough with my answer. With the first line of code you get a path in form of a string to which you can safely read and write. I don't know how you are taking a picture but you can safe it there. Then you can upload this file and after succes you just delete it with the second part of the code. – Epig Aug 11 '18 at 19:58
0

I would recommend using Cloudinary to save your images, his api is very complete.

Cloudinary cloudinary = new Cloudinary(ObjectUtils.asMap(
            "cloud_name", "your_cloud_name", "api_key", "your_api_key", "api_secret", "your_api_key"));
cloudinary.uploader().upload("sample.jpg", ObjectUtils.emptyMap());

You can find more information about your documentation here.

I hope I've helped!