How to send image data to server from Android

前端 未结 5 560
孤独总比滥情好
孤独总比滥情好 2020-12-16 07:53

I am trying to write an Android application that will take a picture, put the data (byte[]) in an object along with some metadata, and post that to an AppEngine server where

5条回答
  •  时光说笑
    2020-12-16 08:47

    As code is provided by three person so you can select any of them(or you will get a lot of example on google). There are three possiblity 1)first you have image in your sdcard

    2)you are downloading image from server and then sending

    3)Images are store in DataBase as blob

    The best approach considering each case-

    1)If your Image is store in sdcard then simply fecth image Convert into bitmap ->byteArray ->String and send to server

    2)If you are downloading images from server and then sending to another URL.Then download all image URL store in DataBase Table.Later on when you need to send to server fetch url,download image and store in cache memory.then similarly send it server and refresh cache memory

    3)Its recommend not to store a lot of image in DB.But in case you have neccessity of doing it then getBlob convert into byte array and send to server

    Sending Image To server

    Reading blob

    Reading from sdcard

    List drawablesId = new ArrayList();
    int picIndex=12345;
     File sdDir = new File("/sdcard/pictures");
    File[] sdDirFiles = sdDir.listFiles();
    for(File singleFile : sdDirFiles)
    {
    Drawable.createFromPath(singleFile.getAbsolutePath());
    / you can create Bitmap from drawable
     }
    

    Hope it will help you

提交回复
热议问题