2013-05-03 57 views
1

有沒有什麼辦法可以將我的錄音機中的多媒體文件(如音頻)或從我的android應用程序中的相機功能中的照片上傳到Microsoft Azure?如何從android應用程序將多媒體文件上傳到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); 
} 
} 

} 

回答

0

代碼如果你有一個Windows Azure存儲帳戶,您可以創建一個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); 
    } 
} 
+0

這是如何使用「發送」按鈕?坦率地說,我對如何將多媒體文件從android應用程序上傳到移動服務中的blob存儲的代碼非常混淆。 – 2013-05-06 02:34:49

相關問題