0
선택한 이미지를 Android 장치에서 Azure Blob 저장소로 업로드하려고합니다.안드로이드 - Azure Storage Blob에 이미지를 업로드하는 방법?
하지만 내 코드에 실패
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
제발 도와주세요!
이import com.microsoft.windowsazure.services.core.storage.*;
import com.microsoft.windowsazure.services.blob.client.*;
public class MainActivity extends Activity {
public static final String storageConnectionString =
"DefaultEndpointsProtocol=http;" +
"AccountName=myName;" +
"AccountKey=YOLO";
Uri currImageURI;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// To open up a gallery browser
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),1);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
// currImageURI is the global variable I'm using to hold the content:// URI of the image
currImageURI = data.getData();
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setText(currImageURI.toString());
//Here starts the code for Azure Storage Blob
try{
// Retrieve storage account from connection-string
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
// Create the blob client
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
// Get a reference to a container
// The container name must be lower case
CloudBlobContainer container = blobClient.getContainerReference("mycontainer");
// Create the container if it does not exist
container.createIfNotExist();
// 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("myimageYdolo.jpg");
File source = new File(currImageURI.toString());
blob.upload(new FileInputStream(source), source.length());
}
catch(Exception e){
}
}
}
}
원래 계정 키가 표시되지 않습니다. 그러나 일반 Java 프로젝트를 만들 때 원래 계정 키가 작동합니다. 안드로이드에서만 실패합니다 ... – Christer
원래 계정 키가 포함되지 않았다는 말이 있습니다. 예외 메시지 란 무엇입니까? –
04-09 18 : 54 : 00.921 : E/AndroidRuntime (7473) : 치명적인 예외 : 주 04-09 18 : 54 : 00.921 : E/AndroidRuntime (7473) : java.lang.NoClassDefFoundError : com.microsoft.windowsazure. services.core.storage.CloudStorageAccount 04-09 18 : 54 : 00.921 : E/AndroidRuntime (7473) : \t at com.example.uploadtest.MainActivity.onActivityResult (MainActivity.java:63) 04-09 18:54 : 00.921 : E/AndroidRuntime (7473) : \t android.app.Activity.dispatchActivityResult (Activity.java:5385) 04-09 18 : 54 : 00.921 : E/AndroidRuntime (7473) : \t android.app.ActivityThread. deliverResults (ActivityThread.java:3843) – Christer