YITechnology / YIOpenAPI

YI Open API provides mobile SDKs and reference designs for software developers and hardware makers to build cool apps and products with YI 4K Action Cameras
Other
345 stars 76 forks source link

Downloaded image files are corrupted #49

Closed rahmatnazali closed 7 years ago

rahmatnazali commented 7 years ago

Hi! :)

So I have a YI 4k Action Camera. Using YI open API, I'm trying to make Android apps that control the camera, capture a photo, and download the captured photo to an external storage on my device.

All were working well, until I try to download the image captured using ActionCamera.downloadFile("YDXJXXXX.JPG"). Here's the detail:

Did I make a mistakes here? Please let me know.

Thanks in advance.

P.S. These are the codes to call the downloadFile() function, though I'm not sure if this will helps:

public void downloadAFile(String fileName){
        String filePath = Constant.externalStoragePath;
        filePath = filePath + fileName;

        this.downloadFile(fileName, filePath, new ActionCameraCommandCallback1<DownloadTask>() {
            @Override
            public void onInvoke(DownloadTask downloadTask) {
                onCameraSucceedDownloadFile(downloadTask);
            }
        }, new ActionCameraCommandCallback1<YICameraSDKError>() {
            @Override
            public void onInvoke(YICameraSDKError yiCameraSDKError) {
                onCameraFailedDownloadFile(yiCameraSDKError);
            }
        });
    }

public void onCameraSucceedDownloadFile(DownloadTask downloadTask){
        Log.i(TAG, " (downloadTask.downloadedBytes/(float)downloadTask.totalBytes*100) +"% downloading image to " + downloadTask.destFilePath);

        // and tell me when download finished
        if(downloadTask.downloadedBytes == downloadTask.totalBytes){
            Log.i(TAG, "download finished " + downloadTask.destFilePath + "at " + (downloadTask.downloadedBytes/(float)downloadTask.totalBytes * 100 + "%");
        }
    }
knkpxt commented 7 years ago

Hi rahmatnazali! I also have same problems. I successfully downloaded file through my app but got corrupted file. If you open file in binary mode you will see that data is scattered - there are empty spaces between data stream. Hope this issue will be handled fast

rahmatnazali commented 7 years ago

To @knkpxt and other people having the same issue, I found the workaround! :) This is not an elegant way, but at least this works.

Before moving further, you guys would need to find the address of the camera's IP, which is mCameraIP variable inside the API. In my case, I made a brand new custom API just to print/log the mCameraIP, and found that (ofcourse) the IP address is 192.168.42.1, just like the IP we used to connect to the camera. I tested it for like 20 times and the camera IP address did not change, so I assume that it was a static address.

So after knowing where to download the files, I just use Glide to download the image via android, using the code from here, or like so:

Bitmap theBitmap = Glide.
        with(getBaseContext()).
        load("http://192.168.42.1/DCIM/100MEDIA/YDXJXXXX.JPG").
        asBitmap().
        into(100, 100). // Width and height, fill it with (Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL) for the original size
        get();

you can then able to modify the image or even save it to external storage.

This solution makes me able to continue the project.

I hope this helps :)

Water-bamboo commented 7 years ago

Hi all, @knkpxt @rahmatnazali This issue was just fixed.

rahmatnazali commented 7 years ago

Hi @Water-bamboo , thanks for answering my issue :)

Super glad to hear you guys are on it. If you guys need another informations from me to provide regarding this issue, please let me know :)

-- Edit: Thanks a million for this fix! :)

Water-bamboo commented 7 years ago

Please pull new code from master branch.

rahmatnazali commented 7 years ago

@Water-bamboo Thanks! I already downloaded the newest JAR from master branch, if that is what you mean.