Try to upload a generated pdf to firebase storage and it didn’t show recognize file type as pdf. I used iText7 to generate the pdf. I didn’t understand why.
This is the method that used to upload the pdf.
`public async Task UploadQRCode(Stream QRCode, string fileName) {
try {
String nameNew = $”{fileName}”;
var task = new FirebaseStorage(_configuration["Firebase:ProjectId"], new FirebaseStorageOptions {
ThrowOnCancel = true
}).Child("QR Codes").Child(nameNew).PutAsync(QRCode);
var downloadURL = await task;
return downloadURL;
} catch (Exception e) {
Console.WriteLine("Error uploading file: " + e.Message);
throw;
}
}`
This is the method that used to generate the pdf.
`public byte[] GenerateSurgicalInventoryQRCode(string categoryId, string itemId) {
var url=${_configuration["BaseURL:Frontend"]}/mlt/inventorysurgical/{categoryId}/{itemId}";
QRCodeGenerator qrGenerator = new QRCodeGenerator();
QRCodeData qrCodeData = qrGenerator.CreateQrCode(url, QRCodeGenerator.ECCLevel.H);
BitmapByteQRCode bitMap = new BitmapByteQRCode(qrCodeData);
var QRCodeBytes = bitMap.GetGraphic(5);
using var memoryStream = new MemoryStream();
var image = Image.FromStream(new MemoryStream(QRCodeBytes));
var width = image.Width;
var height = image.Height;
var pageSize = new PageSize(width, height);
var pdfWriter = new PdfWriter(memoryStream);
var pdfDocument = new PdfDocument(pdfWriter);
var document = new Document(pdfDocument, pageSize);
var imageData = new iText.Layout.Element.Image(iText.IO.Image.ImageDataFactory.Create(QRCodeBytes));
document.Add(imageData);
document.Close();
return memoryStream.ToArray();
}
}`
This is how I use those in controller
`var surgicalInventoryId = _idGenerator.GenerateSurgicalInventoryId();
byte[] QRCode = _qrGenerator.GenerateSurgicalInventoryQRCode(newSurgicalItem.SurgicalCategoryID, surgicalInventoryId);`
var QRurl = await _storageService.UploadQRCode(new MemoryStream(QRCode), surgicalInventoryId);`
What I need is to upload a QR to the firebase as pdf and retrieve using embed in front end. But there is a issue with the uploaded file to the firebase storage. Can anyone help?
Ann Gomez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.