1

有什么方法可以将多媒体文件(例如我的录音机中的音频或我的相机功能中的照片)从我的 android 应用程序上传到 Microsoft Azure 中?

我查看了所有给出的教程,例如服务器端和客户端,并将代码插入到我的项目中。但是我究竟如何通过应用程序上的“发送”按钮上传它们?

请指教。以下是我的基本相机应用程序代码

package com.example.testproject;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;

public class Camera extends Activity{

ImageView iv;

public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.camera);


iv = (ImageView) findViewById(R.id.imageView1);
Button btn = (Button) findViewById(R.id.btnPhoto);
btn.setOnClickListener(new OnClickListener(){

    public void onClick(View v){
        Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, 0);
    }
});

}

protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode == 0)
{
    Bitmap theImage = (Bitmap) data.getExtras().get("data");
    iv.setImageBitmap(theImage);
}
}

 }
4

1 回答 1

0

如果您有 Windows Azure 存储帐户,则可以创建一个 blob 容器,然后将媒体文件上传到存储在容器中的 blob。您的应用程序将使用共享访问字符串或存储的访问策略来控制客户端对这些文件的访问。例如,以下代码作为 Java 控制台应用程序运行,并将本地 .jpg 文件以及一些解释性元数据上传到云中的 blob。

public class SASmeta 
{
public static void main(String[] args) throws URISyntaxException, FileNotFoundException, StorageException, IOException 
   {                        
   URI baseuri = new URI("http://grassy.blob.core.windows.net");
   CloudBlobClient blobclient = new CloudBlobClient(baseuri);
   MyUploadBlob("container1","sr=c&sv=2012-02-12&sig=b%2BK%2FmX8r7dLCVxs5PSPmmji1L6kSxNupp9SKF7yj27w%3D&si=r",blobclient);          
   }

public static void MyUploadBlob(String containerName, String containerSAS, CloudBlobClient blobClient) throws URISyntaxException, StorageException, FileNotFoundException, IOException
   {    
   String blobName = "image1.jpg";  
   String localFileName = "c:\\myimages\\image1.jpg";  
   URI uri = new URI(blobClient.getEndpoint().toString() + "/" + containerName + "/" + blobName + "?" + containerSAS);
   CloudBlockBlob sasBlob = new CloudBlockBlob(uri, blobClient);    
   HashMap<String, String> user = new HashMap<String, String>();    
   user.put("firstname", "Joe");
   user.put("lastname", "Smith" );
   user.put("age", "28");
   user.put("presenter", "no");  
   sasBlob.setMetadata(user);
   File fileReference = new File(localFileName);
   sasBlob.upload(new FileInputStream(fileReference), fileReference.length());
   System.out.println("The blob: " + blobName + " has been uploaded to:");
   System.out.println(uri);
   }
}  
于 2013-05-03T21:16:29.790 回答