2017-10-18 25 views

回答

2

在這裏,我們將嘗試使用簡單的上傳的谷歌雲存儲API JSON在要求上傳圖片到火力地堡存儲。

1)您需要在FireBase控制檯上創建項目才能開始。您可以使用鏈接在FireBase控制檯創建項目https://console.firebase.google.com/?authuser=0

2)轉到控制檯並導航到選項,指出存儲。如果項目創建是正確的,你會得到一個在默認存儲桶中創建的存儲,例如imageupload.appspot.com就我而言。

3)現在我們需要的URL是我們使用郵遞員發佈我們的圖像。您可以通過將圖像上傳到存儲設備來獲取網址。因此上傳圖像。

enter image description here

點擊文件的位置,你會得到上傳圖片的URL。例如:

http://firebasestorage.googleapis.com/v0/b/imageupload.appspot.com/o/IMG-20170630-WA0003.jpg?alt=media&token=f59a9a31-65d7-4e5b-88cf-fc117deacc21在那裏我們張貼圖像所需的網址是:http://firebasestorage.googleapis.com/v0/b/imageupload.appspot.com/o

4)現在改變規則火力地堡貯存:

service firebase.storage { 
    match /b/{bucket}/o { 
    match /{allPaths=**} { 
     allow read, write; 
    } 
    } 
} 

這將允許公衆訪問您的網址。您可以在http://firebase.google.com/docs/storage/security/start

6)閱讀更多關於它發送一個簡單的上傳請求: 要使用簡單的上傳,創建POST請求方法的/上傳URI。

6-a)添加查詢參數uploadType = media

例如,對於一個名爲myBucket鬥:

POST https://firebasestorage.googleapis.com/v0/b/imageupload.appspot.com/o?uploadType=media

6-B)添加名稱查詢參數來確定哪些資源上載關聯。

例如,指定一個對象的名稱是myObject的:

POST https://firebasestorage.googleapis.com/v0/b/imageupload.appspot.com/o?uploadType=media&name=myObject

6-c)中的文件的數據添加到所述請求機構。

6-d)set contentType:image/png因爲我從郵遞員上傳了一張png圖片。

6-e)發送請求。

enter image description here

enter image description here

相關問題