简体   繁体   English

Azure Android Blob上传IOException

[英]Azure Android Blob Upload IOException

I've been trying to integrate azure blob storage with my android app, but I've been having trouble. 我一直在尝试将azure blob存储与我的android应用程序集成,但是遇到了麻烦。 I'm trying to upload a text file to the server, but I an IOException error and the following log: 我正在尝试将文本文件上传到服务器,但是出现IOException错误和以下日志:

getTopLevelResources: /data/app/com.tmacstudios.topmeme-1/base.apk / 1.0 running in com.tmacstudios.topmeme rsrc of package com.tmacstudios.topmeme
09-10 14:40:45.302 16945-16945/com.tmacstudios.topmeme I/InjectionManager: Inside getClassLibPath + mLibMap{0=, 1=}
09-10 14:40:45.302 16945-16945/com.tmacstudios.topmeme D/ResourcesManager: For user 0 new overlays fetched Null
09-10 14:40:45.312 16945-16945/com.tmacstudios.topmeme I/InjectionManager: Inside getClassLibPath caller 
09-10 14:40:45.322 16945-16945/com.tmacstudios.topmeme W/System: ClassLoader referenced unknown path: /data/app/com.tmacstudios.topmeme-1/lib/arm64
09-10 14:40:45.802 16945-16945/com.tmacstudios.topmeme W/System: ClassLoader referenced unknown path: /data/app/com.tmacstudios.topmeme-1/lib/arm64
09-10 14:40:45.812 16945-16945/com.tmacstudios.topmeme D/InjectionManager: InjectionManager
09-10 14:40:45.812 16945-16945/com.tmacstudios.topmeme D/InjectionManager: fillFeatureStoreMap com.tmacstudios.topmeme
09-10 14:40:45.812 16945-16945/com.tmacstudios.topmeme I/InjectionManager: Constructor com.tmacstudios.topmeme, Feature store :{}
09-10 14:40:45.812 16945-16945/com.tmacstudios.topmeme I/InjectionManager: featureStore :{}
09-10 14:40:46.062 16945-16945/com.tmacstudios.topmeme W/ResourcesManager: getTopLevelResources: /data/app/com.tmacstudios.topmeme-1/base.apk / 1.0 running in com.tmacstudios.topmeme rsrc of package com.tmacstudios.topmeme
09-10 14:40:46.062 16945-16945/com.tmacstudios.topmeme W/ResourcesManager: getTopLevelResources: /data/app/com.tmacstudios.topmeme-1/base.apk / 1.0 running in com.tmacstudios.topmeme rsrc of package com.tmacstudios.topmeme
09-10 14:40:46.162 16945-16945/com.tmacstudios.topmeme W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
09-10 14:40:46.322 16945-16945/com.tmacstudios.topmeme E/TopMeme: successful connection to server
09-10 14:40:46.322 16945-16945/com.tmacstudios.topmeme E/TopMeme: upload beginning for clueful_log.txt @ /storage/emulated/0/clueful_log.txt
09-10 14:40:46.332 16945-16945/com.tmacstudios.topmeme E/TopMeme: File size: 111394
09-10 14:40:46.332 16945-16945/com.tmacstudios.topmeme E/TopMeme: available: 111394
09-10 14:40:46.342 16945-16995/com.tmacstudios.topmeme I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
09-10 14:40:46.342 16945-16995/com.tmacstudios.topmeme I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err: java.io.IOException
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.microsoft.azure.storage.core.Utility.initIOException(Utility.java:592)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.microsoft.azure.storage.blob.BlobOutputStream.close(BlobOutputStream.java:309)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.microsoft.azure.storage.blob.CloudBlockBlob.upload(CloudBlockBlob.java:679)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.microsoft.azure.storage.blob.CloudBlockBlob.upload(CloudBlockBlob.java:595)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.tmacstudios.topmeme.MainActivity.uploadFile(MainActivity.java:163)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.tmacstudios.topmeme.MainActivity.onCreate(MainActivity.java:84)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at android.app.Activity.performCreate(Activity.java:6876)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at android.app.ActivityThread.access$1100(ActivityThread.java:222)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at android.os.Looper.loop(Looper.java:158)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:7229)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
09-10 14:40:46.472 16945-16945/com.tmacstudios.topmeme W/System.err: Caused by: com.microsoft.azure.storage.StorageException: Network operations may not be performed on the main thread.
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:188)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.microsoft.azure.storage.blob.CloudBlockBlob.commitBlockList(CloudBlockBlob.java:324)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.microsoft.azure.storage.blob.BlobOutputStream.commit(BlobOutputStream.java:339)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.microsoft.azure.storage.blob.BlobOutputStream.close(BlobOutputStream.java:306)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:    ... 16 more
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err: Caused by: android.os.NetworkOnMainThreadException
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1273)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:249)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at libcore.io.IoBridge.recvfrom(IoBridge.java:549)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at java.net.PlainSocketImpl.read(PlainSocketImpl.java:481)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.android.okhttp.okio.Okio$2.read(Okio.java:140)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.android.okhttp.okio.AsyncTimeout$2.read(AsyncTimeout.java:211)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.android.okhttp.okio.RealBufferedSource.exhausted(RealBufferedSource.java:70)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.android.okhttp.internal.http.HttpConnection.isReadable(HttpConnection.java:165)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.android.okhttp.Connection.isReadable(Connection.java:1524)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.android.okhttp.OkHttpClient$1.isReadable(OkHttpClient.java:91)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.android.okhttp.internal.http.HttpEngine.createNextConnection(HttpEngine.java:475)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.android.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:465)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:447)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:353)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:468)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:118)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:249)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:     at com.microsoft.azure.storage.core.ExecutionEngine.executeWithRetry(ExecutionEngine.java:103)
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme W/System.err:    ... 19 more
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme E/TopMeme: upload failed: java.io.IOException
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme D/Activity: performCreate Call Injection manager
09-10 14:40:46.482 16945-16945/com.tmacstudios.topmeme I/InjectionManager: dispatchOnViewCreated > Target : com.tmacstudios.topmeme.MainActivity isFragment :false
09-10 14:40:46.502 16945-16945/com.tmacstudios.topmeme D/SecWifiDisplayUtil: Metadata value : SecSettings2
09-10 14:40:46.502 16945-16945/com.tmacstudios.topmeme D/ViewRootImpl: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{8ada019 I.E...... R.....ID 0,0-0,0}
09-10 14:40:46.512 16945-17007/com.tmacstudios.topmeme D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
09-10 14:40:46.562 16945-16945/com.tmacstudios.topmeme V/ActivityThread: updateVisibility : ActivityRecord{50af8de token=android.os.BinderProxy@e66a3c9 {com.tmacstudios.topmeme/com.tmacstudios.topmeme.MainActivity}} show : true
09-10 14:40:46.652 16945-17007/com.tmacstudios.topmeme D/libEGL: loaded /vendor/lib64/egl/libGLES_mali.so
09-10 14:40:46.672 16945-17007/com.tmacstudios.topmeme D/libEGL: eglInitialize EGLDisplay = 0x7f8747f178
09-10 14:40:46.672 16945-17007/com.tmacstudios.topmeme I/OpenGLRenderer: Initialized EGL, version 1.4

                                                                         [ 09-10 14:40:46.672 16945:17007 D/         ]
                                                                         ro.exynos.dss isEnabled: 0
09-10 14:40:46.682 16945-17007/com.tmacstudios.topmeme D/mali_winsys: new_window_surface returns 0x3000,  [1440x2560]-format:1
09-10 14:40:46.692 16945-16945/com.tmacstudios.topmeme W/DisplayListCanvas: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
09-10 14:40:46.752 16945-16945/com.tmacstudios.topmeme I/InjectionManager: dispatchCreateOptionsMenu :com.tmacstudios.topmeme.MainActivity
09-10 14:40:46.752 16945-16945/com.tmacstudios.topmeme I/InjectionManager: dispatchPrepareOptionsMenu :com.tmacstudios.topmeme.MainActivity
09-10 14:40:46.752 16945-16945/com.tmacstudios.topmeme D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 96 - 0, 0) vi=Rect(0, 96 - 0, 0) or=1
09-10 14:40:46.752 16945-16945/com.tmacstudios.topmeme I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@e66a3c9 time:331880753

Here is my function that's calling that. 这是我正在调用的函数。 I can confirm that the file path exists: 我可以确认文件路径存在:

void uploadFile(String filePath, String name){
        Log.e("TopMeme","upload beginning for "+name+" @ "+filePath);
        try
        {
            // Retrieve storage account from connection-string.
            CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);

            // Create the blob client.
            CloudBlobClient blobClient = storageAccount.createCloudBlobClient();

            // Retrieve reference to a previously created container.
            CloudBlobContainer container = blobClient.getContainerReference("memecontainer");

            // Create or overwrite the "myimage.jpg" blob with contents from a local file.
            CloudBlockBlob blob = container.getBlockBlobReference(name);
            File source = new File(filePath);
            Log.e("TopMeme","File size: "+source.length());
            FileInputStream fileInputStream = new FileInputStream(source);
            Log.e("TopMeme","available: "+fileInputStream.available());
            blob.upload(fileInputStream, source.length());
            Log.e("TopMeme","upload function completed");
        }
        catch (Exception e)
        {
            // Output the stack trace.
            e.printStackTrace();
            Log.e("TopMeme","upload failed: "+e);
        }
    }

So it turns out that in Azure you can't do anything networking wise on your main android thread, so you have to do it on another thread. 事实证明,在Azure中,您无法在主要的Android线程上进行任何明智的联网操作,因此您必须在另一个线程上进行。 Here is my new function: 这是我的新功能:

void uploadFile(final String filePath,final String name){
        Log.e("TopMeme","upload beginning for "+name+" @ "+filePath);

        //cant perform network tasks on main thread
        AsyncTask<Void,Void,Void> task = new AsyncTask<Void,Void,Void>(){
            @Override
            protected Void doInBackground(Void... params) {
                try
                {
                    // Retrieve storage account from connection-string.
                    CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);

                    // Create the blob client.
                    CloudBlobClient blobClient = storageAccount.createCloudBlobClient();

                    // Retrieve reference to a previously created container.
                    CloudBlobContainer container = blobClient.getContainerReference("memecontainer");

                    /*
                    //create blob if it doesn't exist - hopefully resolves bugs
                    container.createIfNotExists();

                    // Create a permissions object.
                    BlobContainerPermissions containerPermissions = new BlobContainerPermissions();

                    // Include public access in the permissions object.
                    containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER);

                    // Set the permissions on the container.
                    container.uploadPermissions(containerPermissions);
                    */

                    // Create or overwrite the "myimage.jpg" blob with contents from a local file.
                    CloudBlockBlob blob = container.getBlockBlobReference(name);
                    File source = new File(filePath);
                    Log.e("TopMeme","File size: "+source.length());
                    FileInputStream fileInputStream = new FileInputStream(source);
                    Log.e("TopMeme","available: "+fileInputStream.available());
                    blob.upload(fileInputStream, source.length());
                    Log.e("TopMeme","upload function completed");
                }
                catch (Exception e)
                {
                    // Output the stack trace.
                    e.printStackTrace();
                    Log.e("TopMeme","upload failed: "+e);
                }
                return null;
            }
        };

        task.execute();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM