'Faster way to transfer image from android to web interface
What is the fastest transfer to send an image from the android app to a php web system? I have tried sending the images to firebase storage and the url to realtime, and in the web interface I list these images to show them as a video. But this way the transitions are very slow. So I ask what is the best way? Via retrofit? socket? Or another way of transfer that is faster than the one I showed you? In short: I want to transmit the screen from android to a website, but the problem is that I capture several images one by one.
//TRANSFOMAR BITMAP EM ARRAY DE BYTES
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 5, baos);
byte[] dadosImagem = baos.toByteArray();
//criar nome unico de imagem
//String nomeImagem = UUID.randomUUID().toString();
StorageReference imagemRef = storageReference
.child("imagens")
.child("screenshot")
.child(idUser)
.child(IMAGES_PRODUCED+".jpeg");
//fazer upload da imagem
UploadTask uploadTask = imagemRef.putBytes(dadosImagem);
//se o upload foi feito com sucesso iremos inserir a URL da imagem no realtime
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
//em versoes anteriores do a gente recuperava assim taskSnapshot.getDownloadUrl();
//recuperar a url para inserir no realtime
imagemRef.getDownloadUrl().addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
//aqui temos a url da imagem
String url = task.getResult().toString();
Log.d("TAG", IMAGES_PRODUCED + url);
//grava a url recuperada da imagem no realtime
Imagem imagem = new Imagem();
imagem.setUrl(url);
imagem.setIdUsuario(idUser);
imagem.salvarImagem();
sistema_web.php
Here on the web site with php and js I list the url of the images that were registered in firebase realtime.
<script type="text/javascript">
firebase.database().ref('screenshot/'<?=$_GET['idUserFirebase']?>).on('value', (snapshot)=>{
snapshot.forEach(item => {
//console.log(snapshot.val());
//var img = document.querySelector("#screenshot");
//img.setAttribute('src', item.key);
let chave = item.key;
let dado = item.val();
console.log(chave, dado);
var img = document.querySelector("#screenshot");
img.setAttribute('src', dado);
});
});
</script>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
