After generated downloadURL in firebase using:
{
...
let url = uploadTask.snapshot.downloadURL;
...
}
the url content is something similar:
https://firebasestorage.googleapis.com/v0/b/sd2ds-.23.appspot.com/o/Usr%2FEls%2 ...
No worries in using in the browser or HTML tags, however, when I try to use the url generated in photoURL an error is generated:
The photoURL field must be a valid URL.
I already tried use decodeURI(url) but nothing changed.
Firebase generates the url with %2 in / (slash) place and seems be the problem.
Any glue?
Thanks
Use decodeURIComponent.
Suggestion of function with error handling:
const validUrl = require('valid-url');
const fillPhotoUrl = function(p) { return (p && validUrl.isUri(p)) ? decodeURIComponent(p) : null; };
Then use it:
{
...
let url = fillPhotoUrl(uploadTask.snapshot.downloadURL);
...
}
If you want to know the difference between decodeURI and decodeURIComponent, see this question.
Related
I need some help to figure it our why I am getting error when using macthes API, this is my code:
export async function searchCars(query) {
await connect();
const repository = client.fetchRepository(schema);
const cars = await repository
.search()
.where("make")
.eq(query)
.or("model")
.eq(query)
.or("description")
.matches(query)
.return.all();
return cars;
}
And I am getting this error when making API request
May I ask for help?
Many thanks ~~
I did remove the macthes() API, the whole query works, and I can get results back.
If i add it back, the APi will return redis error ...
Expectation: I would like to do text search which matches the paragraph text, then return the record(s).
Sorry, I think I have figured it our, the issue is we need to ensure the scheme field type must be text rather than string, something like below:
description: { type: "text", textSearch: true },
So I am trying to have my code do something if the URL contains this: https://kith.com/throttle/queue?
After the '?' there can be anything, so I only want it to identify 'https://kith.com/throttle/queue?'
I am using puppeteer and want it to work like this:
If the URL contains 'https://kith.com/throttle/queue?' then wait until it passes the queue (page.waitForNavigation({ waitUntil: 'networkidle2' }) would work for waiting until it's through the queue
Else (If the URL doesn't contain that): do nothing and go to the next line of code
It is hard to understand how do you get this URL, but if this is a URL of a current page, you can try this:
const url = await page.evaluate(() => location.href);
if(url.startsWith('https://kith.com/throttle/queue?')) {
// Wait for navigation.
} else {
// Do nothing.
}
Pretty new user to Firebase here. I am trying to zip a .wav file from Firebase right now and I am currently stuck on using jszip in order to zip the files from the download URLs I pull from Firebase. The URLs look like this:
https://firebasestorage.googleapis.com/v0/b/instasample-d8eea.appspot.com/o/kick%2F1.wav?alt=media&token=91612541-83e5-4e82-ae1b-b56bc421e36b
Every time I click the download button on my site, this function runs. I successfully get the download URL, and put it into the var urls.
But I get an error that I am not allowed access to this file and an invalid state error. This puzzles me because I am able to manually go to the link and right click -> save target as just fine.
Thank you so much for any suggestions, go easy on me I am new to jszip and Firebase. This is my code:
function download(downloadType) {
//alert(downloadType)
var storageRef = firebase.storage().ref(downloadType + "/" + "1.wav"); //file name
//todo: get 16 random file links, use for loop for thing below
storageRef.getDownloadURL().then(function(url) {
var downloadLink = url; //download link
//////////////////////// do download stuff here ////////////////////////
var zip = new JSZip();
var count = 0;
var zipFilename = "zipFilename.zip";
var urls = [
downloadLink
];
urls.forEach(function(url){
var filename = "filename";
// loading a file and add it in a zip file
JSZipUtils.getBinaryContent(url, function (err, data) {
if(err) {
throw err; // or handle the error
}
zip.file(filename, data, {binary:true});
count++;
if (count == urls.length) {
var zipFile = zip.generate({type: "blob"});
saveAs(zipFile, zipFilename);
}
});
});
thanks to #MikeMcDonald i fixed both of these errors with this post: Firebase Storage and Access-Control-Allow-Origin
I am now getting:
Uncaught Error: This method has been removed in JSZip 3.0, please
check the upgrade guide.
Looks like I can finally move on. Thanks!
I can't find a satisfying answer to my question. Given an image url, I want to download it (without saving it to the disk) and to immediately upload it to an AWS Bucket. Here is my code :
self.downloadImage = function(url){
let response = HTTP.get(url, {
encoding:null // for binary
})
if (!response.headers['content-type'].split('/')[0] == 'image'){
throw new Error("not an image")
}
return {
data : response.content,
contentType : response.headers['content-type']
}
}
self.uploadImage = function(websiteName, imgUrl, callback){
// we retrieve the image
let image = downloadImage(imgUrl)
let imageName = self.extractImageName(imgUrl)
let filename = 'img/' +websiteName + "/" + imageName
let newUrl = `https://s3.${Meteor.settings.AWS.REGION}.amazonaws.com/${Meteor.settings.S3.BUCKET_NAME}/${filename}`
// makes the async function sync like
let putObjectSync = Meteor.wrapAsync(s3Client.putObject, s3Client)
try{
let res = putObjectSync({
Body: image.data,
ContentType : image.contentType,
ContentEncoding: 'base64',
Key: filename,
ACL:'public-read',
Bucket: Meteor.settings.S3.BUCKET_NAME
})
return newUrl
} catch(e) {
return null
}
}
Everything works fine, except that the image seems corrupted. So far I tried :
to use aldeed:http, in order to set the encoding to null when downloading, which seems a good strategy for images
not to use it and to pass the text content of the response directly as the upload body
to add base64 encoding in aws
Still corrupted. I feel very close to the solution, as the image as the correct type and file size, but still won't print in the browser or on my computer. Any idea about how to correctly encode/retrieve the data ?
Okay I found the answer by myself :
aldeed:meteor allow to add a responseType parameter to the get request. We simply need to set this option to buffer, so that we get the data as a buffer. Then we simply give this buffer, with no transformation, as the Body of the upload function.
Is there a way to update a part of the URL reactively without using FlowRouter.go() while using React and react-layout?
I want to change the value in the document that is used to get the document from the DB. For example, if I have a route like ~/users/:username and update the username field in the document, I then have to user FlowRouter.go('profile', {data}) to direct the user to that new URL. The "old" route is gone.
Below is the working version I have, but there are two issues:
I have to use FlowRouter.go(), which is actually a full page refresh (and going back would be a 404).
I still get errors in the console because for a brief moment the reactive data for the component is actually wrong.
Relevant parts of the component are like this:
...
mixins: [ReactMeteorData],
getMeteorData() {
let data = {};
let users = Meteor.subscribe('user', {this.props.username});
if (user.ready())
data.user = user;
return data;
}
...
updateName(username) {
Users.update({_id:this.data.user._id}, {$set:{username}}, null, (e,r) => {
if (!e)
FlowRouter.go('profile', {username});
});
},
...
The route is like this:
FlowRouter.route('/users/:username', {
name: 'profile',
action(params) {
ReactLayout.render(Main, {content: <UserProfile {...params} />});
}
});
The errors I get in the console are:
Exception from Tracker recompute function:
and
TypeError: Cannot read property '_id' of undefined