partial void UploadImageButton_TouchUpInside(UIButton sender) { try { Random rnd = new Random(); string imageName = string.IsNullOrWhiteSpace(imageTitle.Text) ? "Test" + rnd.Next(1000) : imageTitle.Text; StorageReference imagesRef = storageReference.GetChild("images/" + imageName + ".jpg"); imagesRef.PutFile(imagePath, null, HandleStorageGetPutUpdateCompletionHandler); } catch (Exception ex) { ToastIOS.Toast.MakeText("Error " + ex.Message); } }
public Task PutFileAsync(string filePath, MetadataChange?metadata = null, IProgress <IUploadState>?progress = null, CancellationToken cancellationToken = default, PauseToken pauseToken = default) { if (filePath == null) { throw new ArgumentNullException(nameof(filePath)); } var tcs = new TaskCompletionSource <bool>(); var uploadTask = _storageReference.PutFile(NSUrl.FromFilename(filePath), metadata?.ToStorageMetadata(), (storageMetadata, error) => { if (error != null) { tcs.SetException(ExceptionMapper.Map(new NSErrorException(error))); } else { tcs.SetResult(true); } }); if (progress != null) { uploadTask.ObserveStatus(StorageTaskStatus.Progress, snapshot => progress.Report(new StorageTaskSnapshotWrapper(snapshot))); } if (cancellationToken != default) { cancellationToken.Register(uploadTask.Cancel); } if (pauseToken != default) { pauseToken.SetStorageTask(new StorageUploadTaskWrapper(uploadTask)); } return(tcs.Task); }
// [START upload_from_uri] private void UploadFromUri(Android.Net.Uri fileUri) { Log.Debug(TAG, "uploadFromUri:src:" + fileUri.ToString()); // [START get_child_ref] // Get a reference to store file at photos/<FILENAME>.jpg StorageReference photoRef = mStorageRef.Child("photos") .Child(fileUri.LastPathSegment); // [END get_child_ref] // Upload file to Firebase Storage // [START_EXCLUDE] ShowProgressDialog(); // [END_EXCLUDE] Log.Debug(TAG, "uploadFromUri:dst:" + photoRef.Path); var upload = photoRef.PutFile(fileUri) .AddOnSuccessListener(this, this) .AddOnFailureListener(this, this); }
public IStorageTransferTask PutFile(string filePath, IStorageMetadata metadata = null) { return(metadata == null ? _wrapped.PutFile(AndroidUri.FromFile(new File(filePath))).ToAbstract() : _wrapped.PutFile(AndroidUri.FromFile(new File(filePath)), metadata.ToNative()).ToAbstract()); }