本文整理汇总了Java中com.google.firebase.storage.StorageReference.putBytes方法的典型用法代码示例。如果您正苦于以下问题:Java StorageReference.putBytes方法的具体用法?Java StorageReference.putBytes怎么用?Java StorageReference.putBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.firebase.storage.StorageReference
的用法示例。
在下文中一共展示了StorageReference.putBytes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: imageUpload
import com.google.firebase.storage.StorageReference; //导入方法依赖的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));
}
});
}
示例2: uploadImageToFirebase
import com.google.firebase.storage.StorageReference; //导入方法依赖的package包/类
public void uploadImageToFirebase(String url, String imagename, final UploadImageListener listener){
StorageReference ImagesRef = storageRef.child(PrefKeys.IMAGES.toString()).child(UserInfo.getUniqueID()).child(imagename);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(url, options);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] data = baos.toByteArray();
UploadTask uploadTask = ImagesRef.putBytes(data);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
Log.e("fire", exception.toString());
listener.onUploadImageError();
}
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
@SuppressWarnings("VisibleForTests")
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
listener.onUploadImageSuccess(taskSnapshot.getDownloadUrl().toString());
}
});
}
示例3: uploadFile
import com.google.firebase.storage.StorageReference; //导入方法依赖的package包/类
@Override
public Promise<String, BError, SaveImageProgress> uploadFile(byte[] data, String name, String mimeType) {
final Deferred<String, BError, SaveImageProgress> deferred = new DeferredObject<>();
FirebaseStorage storage = FirebaseStorage.getInstance();
StorageReference storageRef = storage.getReferenceFromUrl(BDefines.FirebaseStoragePath);
StorageReference filesRef = storageRef.child("files");
final String fullName = getUUID() + "_" + name;
StorageReference fileRef = filesRef.child(fullName);
UploadTask uploadTask = fileRef.putBytes(data);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
if (DEBUG) Timber.e(e.getCause(), "Firebase storage exception while saving");
deferred.reject(new BError(BError.Code.FIREBASE_STORAGE_EXCEPTION, e));
}
}).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.
deferred.resolve(taskSnapshot.getDownloadUrl().toString());
}
});
return deferred.promise();
}
示例4: imageUpload
import com.google.firebase.storage.StorageReference; //导入方法依赖的package包/类
private void imageUpload(final String documentReference) {
Log.i(TAG, "imageupload");
StorageReference mountainsRef = storageRef.child("post").child(documentReference).child("photo.jpg");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Log.i(TAG, baos.toString());
bitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() / 6, bitmap.getHeight() / 6, true);
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
dialog.dismiss();
postColRef.document(documentReference).delete();
}
}).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();
dialog.dismiss();
Toast.makeText(AddProductActivity.this, "업로드 되었습니다", Toast.LENGTH_SHORT).show();
finish();
Log.d(TAG, String.valueOf(downloadUrl));
}
});
}
示例5: upload
import com.google.firebase.storage.StorageReference; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void upload(byte[] data, String path, @NonNull final UploadCallback callback)
{
StorageReference dataRef = firebaseStorage().getReference().child(path);
UploadTask uploadTask = dataRef.putBytes(data);
processUpload(uploadTask, callback);
}
示例6: onActivityResult
import com.google.firebase.storage.StorageReference; //导入方法依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
String eventId = getIntent().getStringExtra("eventId");
dbRef = FirebaseDatabase.getInstance().getReference().child(Constants.gallery).child(eventId);
Log.d("image_pick_eventId", eventId);
progressDialog = new ProgressDialog(EventGalleryActivity.this);
progressDialog.setIndeterminate(true);
progressDialog.setTitle("Uploading");
progressDialog.setMessage("Taking your memories into space");
progressDialog.setCancelable(false);
if (requestCode == REQUEST_CODE_PICKER && resultCode == RESULT_OK && data != null) {
images = data.getParcelableArrayListExtra(ImagePickerActivity.INTENT_EXTRA_SELECTED_IMAGES);
Log.d("selected images", images.toString());
progressDialog.show();
for(Image image : images) {
Log.d("selected image path", image.getPath());
Uri file = Uri.fromFile(new File(image.getPath()));
Bitmap bitmap = null;
try {
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), file);
} catch (IOException e) {
e.printStackTrace();
}
StorageReference eventGalleryRef = FirebaseStorage.getInstance().getReference().child("gallery/"+eventId+"/"+file.getLastPathSegment());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if(bitmap == null) {
progressDialog.dismiss();
return;
}
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos);
byte[] imageData = baos.toByteArray();
UploadTask uploadTask = eventGalleryRef.putBytes(imageData);
uploadTaskCount++;
// Register observers to listen for when the download is done or if it fails
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle unsuccessful uploads
uploadTaskCount--;
if(uploadTaskCount == 0 && progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
}).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();
pushUrlToDb(downloadUrl);
uploadTaskCount--;
if(uploadTaskCount == 0 && progressDialog.isShowing()) {
Toast.makeText(EventGalleryActivity.this, "All images uploaded", Toast.LENGTH_SHORT).show();
EventGalleryActivity.this.finish();
progressDialog.dismiss();
}
}
});
}
}
}