如何更改代码以从firebase存储而不是本地下载文件

时间:2016-11-12 05:09:43

标签: swift firebase firebase-storage

我是firebase的新手,我怎样才能将文件从本地文件转换为firebase存储

<rewrite>
        <rules>
    <rule name="Hide .php ext">
        <match ignoreCase="true" url="^(.*)"/>
        <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true"/>
            <add input="{REQUEST_FILENAME}.php" matchType="IsFile"/>
        </conditions>
        <action type="Rewrite" url="{R:0}.php"/>
    </rule>
    <rule name="Redirecting .php ext" stopProcessing="true">
        <match url="^(.*).php"/>
        <conditions logicalGrouping="MatchAny">
            <add input="{URL}" pattern="(.*).php"/>
        </conditions>
        <action type="Redirect" url="{R:1}"/>
    </rule>
   </rules>
</rewrite>

1 个答案:

答案 0 :(得分:0)

Hope you already created Firebase project and Uploaded file to storage which you are looking to load please follow the below guide

install pod

# Pull in Firebase Storage features
pod 'FirebaseUI/Storage', '~> 0.6'

// Create a reference with an initial file path and name
let pathReference = storage.reference("images/stars.jpg")

// Create a reference from a Google Cloud Storage URI
let gsReference = storage.referenceForURL('gs://bucket/images/stars.jpg')

// Create a reference from an HTTPS URL
// Note that in the URL, characters are URL escaped!
let httpsReference = storage.referenceForURL('https://firebasestorage.googleapis.com/b/bucket/o/images%20stars.jpg')

now you have three way to fetch

Download in memory

// Create a reference to the file you want to download
let islandRef = storageRef.child("images/island.jpg")

// Download in memory with a maximum allowed size of 1MB (1 * 1024 * 1024 bytes)
islandRef.dataWithMaxSize(1 * 1024 * 1024) { (data, error) -> Void in
  if (error != nil) {
    // Uh-oh, an error occurred!
  } else {
    // Data for "images/island.jpg" is returned
    // ... let islandImage: UIImage! = UIImage(data: data!)
  }
}

Download to a local file

// Create a reference to the file you want to download
let islandRef = storageRef.child("images/island.jpg")

// Create local filesystem URL
let localURL: NSURL! = NSURL(string: "file:///local/images/island.jpg")

// Download to the local filesystem
let downloadTask = islandRef.writeToFile(localURL) { (URL, error) -> Void in
  if (error != nil) {
    // Uh-oh, an error occurred!
  } else {
    // Local file URL for "images/island.jpg" is returned
  }
}

Generate a download URL

// Create a reference to the file you want to download
let starsRef = storageRef.child("images/stars.jpg")

// Fetch the download URL
starsRef.downloadURLWithCompletion { (URL, error) -> Void in
  if (error != nil) {
    // Handle any errors
  } else {
    // Get the download URL for 'images/stars.jpg'
  }
}

fore more info visit [Firebase D][1]

[1]: https://firebase.google.com/docs/storage/ios/download-files you can replace image file with whatever your file is