I am writing code and i want to upload 2 items on database.
These items are : image , document
To be more specific i have the image (i started as base64/png but i accomplished to upload it as .svg)
and a .pdf that i want to upload
export function CreateSVG(ticketID, cb){
//Casts inputs to String
let _ticketID = String(ticketID);
//Makes a QR Code in .svg (string in xml format)
QRCode.toString(_ticketID, {type : "svg"} ,function (err, svg) {
if (err) throw err
//Uploads it to Media Manager
let filePath = uploadImage(svg, _ticketID);
console.log(filePath.fileUrl)
return cb(svg);
})
}
and
//Function that uploads to Media Manager
export function uploadImage(buffer,fileName) {
let _filename = String(fileName);
return mediaManager.upload(
"/SVG/",
buffer,
(_filename+".svg"),
{
"mediaOptions": {
"mimeType": "image/svg+xml",
"mediaType": "image"
},
"metadataOptions": {
"isPrivate": false,
"isVisitorUpload": false,
"context": {
"someKey1": "someValue1",
"someKey2": "someValue2"
}
}
}
);
}
These codes above are just for uploading .svg and works just fine.
But now my .pdf that i create can be in 2 forms : 1) PDF Bytes (i tried blob but not working)
2) Base64 (when i upload i just see the URI)
Also Filesystem(fs) don’t work, right?
Any help?
You can find the right Mime type for the Media Backend if you simply follow the Media Options link.
https://www.wix.com/corvid/reference/wix-media-backend.mediaManager.html#MediaOptions
Mime type of the file to import. The specified value must match the actual mime type of the file’s content.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types
For the full list see here.
https://www.iana.org/assignments/media-types/media-types.xhtml
So as you have already used above in your post, SVG would be image/svg+xml and PDF would be application/pdf.
my problem is that i cannot store base64 [image/png] and [documents/pdf]
at the database. i made svg upload work with the code above. but i want to upload png and pdf in base64 string as a file in database
also 1 more question is how once i upload to media manager get a link to store into my database? i really struggle with this part too
passing base64 pdf ( data:application/pdf;base64,{generatedbase64code})
into this function
//Function that uploads generated pdf to Media Manager
export function uploadPDF(url,name="unknown") {
//Options for upload
let mediaOpt = {
"mediaOptions": {
"mimeType": "application/pdf",
"mediaType": "document"
},
"metadataOptions": {
"isPrivate": false,
"isVisitorUpload": false,
}
}
//Path saved in Media Manager
let folderPath = "/Tickets/"
//Filename with .extension
let fileName =`${name}.pdf`;
//let fileName = "test.pdf";
//The upload function
return mediaManager.upload(folderPath, url, fileName, mediaOpt );
}
which i implemented from here
does nothing! what’s wrong?
Also when i wait for a promise in the working uploadImage i get null (on async function)
let filePath = await uploadImage(svgBuffer, _ticketID);
also this is a backened functions
bump. Still trying after 2 days and i cannot make URI base64 ( data:application/pdf;base64,{generatedbase64code}) upload on media manager.
any help?
Update:
406 - {"error_code":-7751,"error_description":"media type document does not match the actual file mime type text/plain","error_info":{"message":"media type {0} does not match the actual file mime type {1}","args":["document","text/plain"],"key":"wpm_error.mime_type_mismatch"}}
On promise! i understand that mime doesn’t match that’s why .pdf don’t upload but how can i use text/plain?
also uploading png with correct mime type gives
406 - {"error_code":-7751,"error_description":"Failed to get image info."}
example image.png in base64 format i wanna upload an get the error
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHQAAAB0CAYAAABUmhYnAAAAAklEQVR4AewaftIAAAKuSURBVO3BQW7kQAwEwSxC//9yro88NSBIM/YSjIg/WGMUa5RijVKsUYo1SrFGKdYoxRqlWKMUa5RijVKsUYo1SrFGKdYoxRrl4qEkfJNKl4Q3qXRJ+CaVJ4o1SrFGKdYoFy9TeVMSTlSeSMIdKm9KwpuKNUqxRinWKBcfloQ7VO5Iwm9Kwh0qn1SsUYo1SrFGufjPqXRJOFHpkjBJsUYp1ijFGqVYoxRrlGKNUqxRLj5M5ZOScKJyovKEyl9SrFGKNUqxRrl4WRJ+k0qXhE6lS0KncpKEv6xYoxRrlGKNEn8wSBI6lS4JncokxRqlWKMUa5T4gweS0Kl0SehU7kjCicpJEu5QOUlCp3KShE6lS0Kn8kSxRinWKMUa5eIhlS4JTyShU+mS0CWhU+lU7kjCiUqXhBOVbyrWKMUapVijXDyUhDuScKLSJaFT+ctUuiR0Kp9UrFGKNUqxRok/eCAJncodSThR6ZJwh8pJEk5U7khCp/JNxRqlWKMUa5SLD0vCicpJEjqVLgmdyh0qXRJOknCickcSOpUnijVKsUYp1igXD6mcqDyh8kQSOpU7kvCmJHQqbyrWKMUapVijXDyUhG9SeSIJJyp3JOEOlS4JncoTxRqlWKMUa5SLl6m8KQknKicqXRI6lS4JnUqXhE6lS0KncqLypmKNUqxRijXKxYcl4Q6VJ5JwRxLuUOmS0Kn8pmKNUqxRijXKxXAqJ0noVE6ScJKETuWbijVKsUYp1igX/7kkdCpdEp5IQqfSJeEkCXeoPFGsUYo1SrFGufgwlU9SOVG5IwmdyonKX1KsUYo1SrFGuXhZEr4pCXeodEm4Iwl3qJwkoVN5olijFGuUYo0Sf7DGKNYoxRqlWKMUa5RijVKsUYo1SrFGKdYoxRqlWKMUa5RijVKsUYo1yj/gQQfyxLOwIQAAAABJRU5ErkJggg==
Was you able to figure this out? I have a image that i produce on the page for both the visitor to copy and i can save it. How would i save it? Viewing is easy sitting a img element object src but how would i store it and retrieve it when a visitor/users want to see it again?
Please generate/open your own post including your own good described issued situation.
You can link this post, if it is relevant to your issue.
Bumping-up old posts is not the correct behaviour in this forum.
Please also observe the community-guidelines & rules!
You will find all informations here…https://www.wix.com/velo/forum/getting-started