本文整理汇总了Java中com.google.firebase.storage.UploadTask类的典型用法代码示例。如果您正苦于以下问题:Java UploadTask类的具体用法?Java UploadTask怎么用?Java UploadTask使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UploadTask类属于com.google.firebase.storage包,在下文中一共展示了UploadTask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onActivityResult
import com.google.firebase.storage.UploadTask; //导入依赖的package包/类
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RC_SIGN_IN){
if (resultCode == RESULT_OK){
Toast.makeText(this, "Sign in successful", Toast.LENGTH_SHORT).show();
} else if (requestCode == RESULT_CANCELED){
Toast.makeText(this, "Sign in cancelled", Toast.LENGTH_SHORT).show();
finish();
}
} else if (requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK){
Uri selectedImageUri = data.getData();
StorageReference photoRef = mChatPhotoStorageReference.child(selectedImageUri.getLastPathSegment());
photoRef.putFile(selectedImageUri).addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri downloadUrl = taskSnapshot.getDownloadUrl();
FriendlyMessage friendlyMessage = new FriendlyMessage(null, mUsername, downloadUrl.toString());
mMessagesDatabaseReference.push().setValue(friendlyMessage);
}
});
}
}
示例2: putImageInStorage
import com.google.firebase.storage.UploadTask; //导入依赖的package包/类
private void putImageInStorage(StorageReference storageReference, Uri uri, final String key) {
storageReference.putFile(uri).addOnCompleteListener(MainActivity.this,
new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if (task.isSuccessful()) {
FriendlyMessage friendlyMessage =
new FriendlyMessage(null, mUsername, mPhotoUrl,
task.getResult().getDownloadUrl()
.toString());
mFirebaseDatabaseReference.child(MESSAGES_CHILD).child(key)
.setValue(friendlyMessage);
} else {
Log.w(TAG, "Image upload task was not successful.",
task.getException());
}
}
});
}
示例3: onActivityResult
import com.google.firebase.storage.UploadTask; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
if (resultCode == RESULT_OK)
Toast.makeText(this, "Signed in", Toast.LENGTH_SHORT).show();
else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Sign in Cancelled", Toast.LENGTH_SHORT).show();
finish();
}
} else if (requestCode == RC_IMAGE_PICKER && resultCode == RESULT_OK) {
Log.e(TAG, "Error is here");
Uri selectedImageUri = data.getData();
StorageReference photoRef = mChatPhotosStorageReference.child(selectedImageUri.getLastPathSegment());
photoRef.putFile(selectedImageUri).addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri downloadUrl = taskSnapshot.getDownloadUrl();
FriendlyMessage friendlyMessage = new FriendlyMessage(null, mUsername, downloadUrl.toString());
mMessagesDatabaseReference.push().setValue(friendlyMessage);
}
});
}
}
示例4: putImageInStorage
import com.google.firebase.storage.UploadTask; //导入依赖的package包/类
/**
* Guardo la imagen en la base de datos de FCM
* @param storageReference
* @param uri
*/
private void putImageInStorage(StorageReference storageReference, Uri uri) {
storageReference.putFile(uri).addOnCompleteListener(MensajesActivity.this,
new OnCompleteListener<UploadTask.TaskSnapshot>() {
@SuppressWarnings("VisibleForTests")
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if (task.isSuccessful()) {
Mensaje friendlyMessage = new Mensaje(null, mUsername, mPhotoUrl, task.getResult().getDownloadUrl().toString());
friendlyMessage.setSenderUid(usuarioSesion.getUid());
friendlyMessage.setReceiverUid(usuarioChat.getUid());
friendlyMessage.setTimestamp(System.currentTimeMillis());
friendlyMessage.setReceiver(usuarioChat.getUser());
sendMessageToFirebaseUser(friendlyMessage,usuarioChat.getFirebaseToken());
} else {
Log.w("Mensajes", "Image upload task was not successful.",
task.getException());
}
}
});
}
示例5: onActivityResult
import com.google.firebase.storage.UploadTask; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == GALLERY_INTENT && resultCode == RESULT_OK) {
Uri uri = data.getData();
StorageReference filepath = mStorage.child("Photos").child(uri.getLastPathSegment());
filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
downloadURL = taskSnapshot.getDownloadUrl().toString();
Picasso.with(getApplicationContext()).load(downloadURL).into(imageItem);
Toast.makeText(AddItemActivity.this, "Upload Done", Toast.LENGTH_LONG).show();
}
});
}
}
示例6: onActivityResult
import com.google.firebase.storage.UploadTask; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == GALLERY_INTENT && resultCode == RESULT_OK){
showProgressDialog();
Uri uri = data.getData();
StorageReference filePath = mStorage.child("fotos").child(uri.getLastPathSegment());
filePath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
hideProgressDialog();
Uri downloadUri = taskSnapshot.getDownloadUrl();
imageUrl = downloadUri;
Picasso.with(NewPostActivity.this).load(downloadUri).fit().centerCrop().into(mCriminalPicture);
Toast.makeText(NewPostActivity.this, R.string.upload__success, Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
hideProgressDialog();
Toast.makeText(NewPostActivity.this, R.string.upload_failure, Toast.LENGTH_SHORT).show();
}
});
}
}
示例7: uploadImageToFirebase
import com.google.firebase.storage.UploadTask; //导入依赖的package包/类
private void uploadImageToFirebase(Uri file) {
imageFilename = UUID.randomUUID().toString().replaceAll("-", "") + ".jpg";
currentUser = mAuth.getCurrentUser();
StorageReference postedImagesRef = mStorageRef.child(currentUser.getUid()).child(imageFilename);
postedImagesRef.putFile(file)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Get a URL to the uploaded content
imageDownloadUrl = taskSnapshot.getDownloadUrl().toString();
Log.d(TAG, "success: Image upload");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.d(TAG, "failed: Image upload");
}
});
}
示例8: uploadPhoto
import com.google.firebase.storage.UploadTask; //导入依赖的package包/类
public void uploadPhoto() {
final PickSetup setup = new PickSetup().setSystemDialog(true);
PickImageDialog.build(setup).setOnPickResult(new IPickResult() {
/**
* Handle the selected result
* @param r - the selected result
*/
@Override
public void onPickResult(PickResult r) {
StorageTask<UploadTask.TaskSnapshot> uploadTask = getDatabaseManager().updatePlantImage(mPlant.getPhotoPointer() + 1,
mPlant.getPhotoNum() + 1, mPlant.getId(), r.getBitmap());
uploadTask.addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if (task.isSuccessful()) {
loadProfilePhoto();
}
}
});
}
}).show(getActivity().getSupportFragmentManager());
}
示例9: onActivityResult
import com.google.firebase.storage.UploadTask; //导入依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
if (resultCode == RESULT_OK) {
Toast.makeText(this, "Signed in , Oh yeah", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Signed In canceled", Toast.LENGTH_SHORT).show();
finish();
}
}else if (requestCode==RC_PHOTO_PICKER && resultCode == RESULT_OK){
Uri selectedImageUri = data.getData();
StorageReference photoRef = photoStorageReference.child(selectedImageUri.getLastPathSegment());
photoRef.putFile(selectedImageUri).addOnSuccessListener(this, new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri downloadURI = taskSnapshot.getDownloadUrl();
Message friendlyMessage = new Message(null,mUsername,downloadURI.toString());
messageDatabaseReference.push().setValue(friendlyMessage);
}
});
}
}
示例10: onActivityResult
import com.google.firebase.storage.UploadTask; //导入依赖的package包/类
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == RC_SIGN_IN){
if (resultCode == RESULT_OK){
Toast.makeText(getActivity(), "Sign in successful", Toast.LENGTH_SHORT).show();
} else if (requestCode == RESULT_CANCELED){
Toast.makeText(getActivity(), "Sign in cancelled", Toast.LENGTH_SHORT).show();
getActivity().finish();
}
} else if (requestCode == RC_PHOTO_PICKER && resultCode == RESULT_OK){
Uri selectedImageUri = data.getData();
StorageReference photoRef = mChatPhotoStorageReference.child(selectedImageUri.getLastPathSegment());
photoRef.putFile(selectedImageUri).addOnSuccessListener(getActivity(), new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Uri downloadUrl = taskSnapshot.getDownloadUrl();
FriendlyMessage friendlyMessage = new FriendlyMessage(null, mUsername, downloadUrl.toString());
mMessagesDatabaseReference.push().setValue(friendlyMessage);
}
});
}
}
示例11: sendFileFirebase
import com.google.firebase.storage.UploadTask; //导入依赖的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
}
}
示例12: storeUserImageInDatabase
import com.google.firebase.storage.UploadTask; //导入依赖的package包/类
/**
* This method store the user profile image to firebase storage.
* if it stored in storage, the image is load to database of firebase which
* make change in userdata and sets it's image to imageview.
* @param imageUri
*/
public void storeUserImageInDatabase(final Uri imageUri){
FirebaseHelper.getUserImageStorageReference(USER_LINK_FIREBASE)
.putFile(imageUri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Map<String,Object> userImage = new HashMap<String, Object>();
userImage.put("userImage",taskSnapshot.getDownloadUrl().toString());
FirebaseHelper.USERS_DATABASE_REFERENCE.child(USER_LINK_FIREBASE).updateChildren(userImage);
}
});
}
示例13: imageUpload
import com.google.firebase.storage.UploadTask; //导入依赖的package包/类
private void imageUpload() {
Log.i(TAG, "imageupload");
StorageReference mountainsRef = storageRef.child("user").child(mAuth.getUid()).child("profile.jpg");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] data = baos.toByteArray();
UploadTask uploadTask = mountainsRef.putBytes(data);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle unsuccessful uploads
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
Uri downloadUrl = taskSnapshot.getDownloadUrl();
Log.d(TAG, String.valueOf(downloadUrl));
}
});
}
示例14: uploadImage
import com.google.firebase.storage.UploadTask; //导入依赖的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());
}
}
});
}
}
示例15: processUpload
import com.google.firebase.storage.UploadTask; //导入依赖的package包/类
/**
* Add onFailure and onSuccess listeners to uploadTask.
*
* @param uploadTask Upload task which we want to deal with.
* @param callback Callback which will be call from {@link UploadTask#addOnFailureListener(OnFailureListener)} and {@link UploadTask#addOnSuccessListener(OnSuccessListener)}
*/
private void processUpload(UploadTask uploadTask, final UploadCallback callback)
{
uploadTask.addOnFailureListener(new OnFailureListener()
{
@Override
public void onFailure(@NonNull Exception e)
{
callback.onFail(e);
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>()
{
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot)
{
FileMetadata fileMetadata = buildMetadata(taskSnapshot);
callback.onSuccess(fileMetadata);
}
});
}