本文整理汇总了Java中com.google.firebase.storage.StorageReference.putFile方法的典型用法代码示例。如果您正苦于以下问题:Java StorageReference.putFile方法的具体用法?Java StorageReference.putFile怎么用?Java StorageReference.putFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.firebase.storage.StorageReference
的用法示例。
在下文中一共展示了StorageReference.putFile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendFileFirebase
import com.google.firebase.storage.StorageReference; //导入方法依赖的package包/类
private void sendFileFirebase(StorageReference storageReference, final Uri file) {
if (storageReference != null) {
final String name = DateFormat.format("yyyy-MM-dd_hhmmss", new Date()).toString();
StorageReference imageGalleryRef = storageReference.child(name + "_gallery");
UploadTask uploadTask = imageGalleryRef.putFile(file);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e(TAG, "onFailure sendFileFirebase " + e.getMessage());
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Log.i(TAG, "onSuccess sendFileFirebase");
Uri downloadUrl = taskSnapshot.getDownloadUrl();
FileModel fileModel = new FileModel("img", downloadUrl.toString(), name, "");
ChatModel chatModel = new ChatModel(userModel, "", Calendar.getInstance().getTime().getTime() + "", fileModel);
mFirebaseDatabaseReference.child(Constants.events).child(evekey).child(Constants.chatmodel).push().setValue(chatModel);
}
});
} else {
//IS NULL
}
}
示例2: uploadImage
import com.google.firebase.storage.StorageReference; //导入方法依赖的package包/类
private void uploadImage(final Item item) {
if (item.getImageUrl() != null) {
Uri uri = Uri.fromFile(new File(item.getImageUrl()));
StorageReference photoRef = mFirebaseStorage.getReference("users")
.child(mFirebaseUser.getUid())
.child("item_photos")
.child(uri.getLastPathSegment());
StorageMetadata metadata = new StorageMetadata.Builder()
.setContentType("image/webp")
.build();
UploadTask uploadTask = photoRef.putFile(uri, metadata);
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
@SuppressWarnings("VisibleForTests")
Uri downloadUrl = taskSnapshot.getDownloadUrl();
if (downloadUrl != null) {
deleteItemFile(item);
item.setImageUrl(downloadUrl.toString());
mRepository.saveItem(mFirebaseUser.getUid(), item);
mSharedPreferencesHelper.removeImageUploading(item.getId());
}
}
});
}
}
示例3: upload
import com.google.firebase.storage.StorageReference; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void upload(FileHandle file, String path, UploadCallback callback)
{
StorageReference dataRef = firebaseStorage().getReference().child(path);
UploadTask uploadTask = dataRef.putFile(Uri.fromFile(file.file()));
processUpload(uploadTask, callback);
}
示例4: publishPostWithImage
import com.google.firebase.storage.StorageReference; //导入方法依赖的package包/类
private void publishPostWithImage(final Post post, Uri imageUri, final Callbacks.IResultCallback<Post> callback) {
//Uploading Image
String postCategory = post.getCategory();
FirebaseStorage postsImagesStorage = Library.getImageProfilesStorage();
final StorageReference filepath = postsImagesStorage.getReference().child(postCategory)
.child(imageUri.getLastPathSegment());
//Uploading image
final UploadTask uploadTask = filepath.putFile(imageUri);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
e.printStackTrace();
callback.onDataUnavailable();
}
})
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
showLog("UPLOAD POST IMAGE SUCEESS:");
//get the download URL like this:
@SuppressWarnings("VisibleForTests")
Uri downloadUrl = taskSnapshot.getDownloadUrl();
String string_dwload = downloadUrl.toString();
//Get the uploaded image URL.
post.setImgUrl(string_dwload);
// Publish the post, with the image URL
PostsRemoteDataSource.this.publishPost(post, callback);
}
});
}
示例5: uploadImage
import com.google.firebase.storage.StorageReference; //导入方法依赖的package包/类
public UploadTask uploadImage(Uri uri, String imageTitle) {
StorageReference storageRef = storage.getReferenceFromUrl(context.getResources().getString(R.string.storage_link));
StorageReference riversRef = storageRef.child("images/" + imageTitle);
// Create file metadata including the content type
StorageMetadata metadata = new StorageMetadata.Builder()
.setCacheControl("max-age=7776000, Expires=7776000, public, must-revalidate")
.build();
return riversRef.putFile(uri, metadata);
}