Implementing simple and default web share API level 2 code for files, API changes the file name to random.
Just in case I will show here my code of sharing file with API. I said "just in case" because the same occurs to me in official chromestatus site and other sample sites.
async function enviar_gmail(){
const title = document.getElementById('subject').value;
const text = document.getElementById('body-big').value;
const response = await fetch('assets/img/hello.pdf');
const blob = await response.blob();
const filesArray = [new File([blob],'hello.pdf',{type: "application/pdf", lastModified: new Date().getTime()})];
if (!navigator.canShare || !navigator.canShare({files: filesArray})) {
$('.notification').html('No se accepta');
$('.warning').fadeIn('slow');
return false;
}
const shareData = {
title: title,
text: text,
files: filesArray,
};
if (navigator.canShare && !navigator.canShare(shareData)) {
$('.notification').html('No se accepta');
$('.warning').fadeIn('slow');
return false;
}
navigator.share(shareData);
}
Works good except it shows share635287463528173875.pdf as attached file, not hello.pdf.
Doesn´t matter if it is .jpg or .txt.
The same occurs with sharing local input file!
And finally I went to official web share API site and examples which confirmed it:
All links showed random file name of any kind of accepted file types (.txt, .pdf, .jpg) eg.share365645756784578.jpg etc.
So I asked first, is it possible that I am the only one in this world having this problem (which make this API useless) because nobody reports this except one post without solution: HERE
Is it related with my location, Spain, which has no sense but I ask just in case because I am sure it is a BUG because the same error occurs in all test sites I found (see above)?
Tested on mobile chrome V96; Android 11.
If someone can tell me what is going on here with this API and file names.
I was waiting 2 years for Google to finally implements .pdf as accepted file and that my client can share invoice pdf attachment, but no way.
I forgot to say, I tried the same on my wife´s and friend´s mobiles and it shows the same random filename.
Is it a any workaround for this, because obviously all codes I tried are good.
This community is the last chance for me, like now, API is useless.
I am not able to hack and write java in Chromium, it is supposed to be a job of trillion dollar worth company who made it, so my opinion is, if stackoverflow community can´t help, nobody can do it, so I will report it as a bug.
I appreciate any help or suggestions.