当前位置: 首页>>代码示例>>Java>>正文


Java StorageReference.putFile方法代码示例

本文整理汇总了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
    }
}
 
开发者ID:picopalette,项目名称:event-me,代码行数:25,代码来源:MessagingActivity.java

示例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());
                }
            }
        });
    }
}
 
开发者ID:mvescovo,项目名称:item-reaper,代码行数:27,代码来源:ImageUploadService.java

示例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);
}
 
开发者ID:mk-5,项目名称:gdx-fireapp,代码行数:11,代码来源:Storage.java

示例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);
                }
            });
}
 
开发者ID:pedromassango,项目名称:Programmers,代码行数:36,代码来源:PostsRemoteDataSource.java

示例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);
}
 
开发者ID:rozdoum,项目名称:social-app-android,代码行数:11,代码来源:DatabaseHelper.java


注:本文中的com.google.firebase.storage.StorageReference.putFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。