Getting retry limit exceeded error on uploading a few images to Google Storage - firebase-storage

I'm not sure what's going on, because I don't get this issue, but a lot of my users report this issue. I have a page that uploads multiple files (the error is happening at 5). Several users report getting the error "storage/retry-limit-exceeded". What's going on? Please help.
In the code below, each error[i][j] gets the same code, which is "storage/retry-limit-exceeded".
My code looks like:
function SubmitFiles(){
pending=true;
let promises = partsofprobs.map((x,i) => {
return x.map((y,j) => FileUpload(i,j));
});
Promise.all(promises.map(x=>Promise.all(x))).then((values)=>{
//DO SOME STUFF WITH THE VALUES -- code removed for brevity, since the error is thrown by the other function.
});
}
function FileUpload(i,j){
return new Promise((resolve, reject) => {
let file=newpicdata[i][j];
if(file){
currentupload[i][j]=true;
let storageRef = storage.ref();
let fileRef = storageRef.child(examid+'/'+i+'/'+j+'/'+$currentUser.uid+'/'+newfiles[i][j][0].name);
let uploadTask = fileRef.putString(file, 'data_url');
uploadTask.on('state_changed',
function(snapshot) {
// Get task progress, including the number of bytes uploaded and the total number of bytes to be uploaded
let uploadedpercent = (snapshot.bytesTransferred / snapshot.totalBytes)*100;
console.log('Upload is ' + uploadedpercent + '% done');
switch (snapshot.state) {
case 'paused':
console.log('Upload is paused');
break;
case 'running':
console.log('Upload is running');
break;
}
}, function(err) {
console.log("error code: ", err.code);
error[i][j]=err.code;
currentupload[i][j]=false;
reject();
}, function() {
// Upload completed successfully, now we can get the download URL
uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) {
uploadedpicsurls[i][j]=downloadURL;
success[i][j]=true;
currentupload[i][j]=false;
console.log('File available at', downloadURL);
resolve({url:downloadURL,graded:false,score:null,problemindex:i,part:j,grader:null,notes:[],outof:partsofprobs[i][j],beinggradedby:[]});
});
});
}else{
resolve(existingrecord ? existingrecord.solutions[i].parts[j]:{url:null,graded:false,score:0,problemindex:i,part:j,grader:null,notes:[],outof:partsofprobs[i][j],beinggradedby:[]});
}
})
}

Related

Pass Parameters Besides URL in Next JS in Client Side API Fetch

I've been working on calling an internal GetCompanies API through the website client side.
So far I made attempts like this based on search results and documentation
// const fetcher = (includeFiles, folderLocation, SharePointCreds) => fetch(includeFiles, folderLocation, SharePointCreds).then(res => res.json());
// const { data, error } = useSWR('http://localhost:55419/api/SharePoint/GetCompanies', fetcher);
// if (error) return <div>failed to load</div>
// if (!data) return <div>loading...</div>
// render data
//return <div>hello {data}!</div>
useEffect((includeFiles, folderLocation, SharePointCreds) => {
fetch('http://localhost:55419/api/SharePoint/GetCompanies', includeFiles, folderLocation, { method: "POST", body: SharePointCreds})
.then((res) => res.json())
.then((data) => {
console.log("data is ", data)
})
}, [])
if (isLoading) return <p>Loading...</p>
// async function GetCompanies(includeFiles, folderLocation, SharePointCreds){
// const res = await fetch('http://localhost:55419/api/SharePoint/GetCompanies');
// const companies = await res.json();
// }
// return (
// <div>
// <p>{data}</p>
// </div>
// )
corresponding to an API call which works when we test it in Swagger
And I got generic error messages like TypeError: Failed to fetch
I guess the error is in how I pass in includeFiles and folderLocation since I haven't yet found documentation or search results for how to pass in parameters besides the URL, though I could be wrong.
I define all the arguments earlier in the portfolio component for now.
Do you see how else I should pass in includeFiles and folderLocation?
Also, please be kind because I'm learning and doing my best and I've worked on this for a few hours already.

Delete Messages with sockets

It actually should be pretty simple, but I can't seem to get a hang of it.
I want to create a chatroom with sockets.
I already managed it to send Messages, but I want to be able to delete them all.
The code for sending messages:
Server:
let io = socket(server);
io.on('connection', (socket) => {
socket.on('chat', function (data) {
io.sockets.emit('chat', data)
});
}
Client:
let socket = io.connect(window.location.protocol + '//' +
window.location.host);
socket.on('chat', function (data) {
let output: JQuery = $('#output');
let feedback: JQuery = $('#feedback');
output.html(output.html() + '<p><strong>' + data.username + ':<br>
</strong>' + data.message + '</p>');
feedback.html('');
});
function sendMessage() {
let message: JQuery = $('#message');
let username: JQuery = $('#username');
let feedback: JQuery = $('#feedback');
socket.emit('chat', {
message: message.val(),
username: username.val(),
feedback: feedback.val(),
});
message.html('');
}
$(function () {
$('#send').on('click', function () {
sendMessage();
});
}
Thank you in advance!
I already managed it to send Messages, but I want to be able to delete them all.
What do you mean by delete them? They are not stored on backend - it only broadcasting messages to clients.
EDIT
If you want user for just clear chat, according to code you provided - you can just clear output:
...
let output: JQuery = $('#output');
...
let someButton = $('#<SOME BUTTON ID>');
someButton.click(() => {
output.html('');
});
...

PWA Service worker match against specific cache timing issue

Fairly new to SW and Promises (and I'm not that good with JS either!) so I might be missing something obvious.
Users have different sections that they can add and delete and the sections contain images they would add to those sections so I want to use SW to cache those images but want to put them in a section numbered cache so if they delete a section I can easily just delete that cache.
Following some research and tutorials I got this working in the 'fetch' event listener:
var cacheName = `mycache-${id}`;
event.respondWith(
caches.match(event.request, { 'ignoreSearch': true }).then(function (resp) {
return resp || fetch(event.request).then(function (response) {
return caches.open(cacheName).then(function (cache) {
cache.put(event.request, response.clone());
return response;
})
})
})
);
But obviously that's searching all the caches so I assumed it would be more efficient to search the only cache it needs to however this doesn't seem to work, seems like it's hitting the fetch before it can respond with what it might have found in a cache?
var cacheName = `mycache-${id}`;
event.respondWith(
caches.open(cacheName).then(function (cache) {
console.log("Opened cache");
cache.match(event.request, { 'ignoreSearch': true }).then(function (resp) {
console.log("Tried to find a match");
return resp || fetch(event.request).then(function (response) {
return caches.open(cacheName).then(function (cache) {
cache.put(event.request, response.clone());
return response;
})
})
})
})
);
It is putting the images in the named cache so am I doing something stupid here, I understand that Promises are async but my understanding was the '.then' will wait for a response before it continues.
Ok well it appears it was a simple case of a missing return!
This line:
cache.match(event.request, { 'ignoreSearch': true }).then(function
(resp) {
should have been
return cache.match(event.request, { 'ignoreSearch': true
}).then(function (resp) {

ERROR:the operation couldn't be completed. (com.facebook.sdk error 5.)

I am getting sdk problem, what I change in the code for removing error?
Please help me, I am new in titanium.
var f = Ti.Filesystem.getFile('pumpkin.jpg');
var blob = f.read();
var data = {
message: 'This is a pumpkin',
picture: blob
};
Titanium.Facebook.requestWithGraphPath('me/photos', data, 'POST', function(e) {
if (e.success) {
alert("Success! From FB: " + e.result);
} else {
if (e.error) {
alert(e.error);
} else {
alert("Unkown result");
}
}
});
you are trying to execute example code from online doc so if you are using traditional structure then put one pic with pumpkin.jpg in resources directory because i think that file should be missing.
and be sure that you are calling after login.

Baasbox and Javascript

I'm trying BaaSbox, a free Backend as a Service. But it has no out-of-the-box Javascript support I can use right away (yet, only iOS and Android)
I'm having trouble sending the right curl command from javascript, anyone happen to know a good resource or a simple working $.ajax template? I've tried a few examples from stackoverflow, but none of them specifically aimed at BaaSbox.
I've tried following the Java instructions on their site here. Just making a simple login work, but I keep getting the wrong responses from the server.
Or on the other hand, anyone know a good, free alternative to BaaSbox? I just want to be able to install it on my own server, no paid plans or whatever.
in the download page there is a preliminary version of the JS SDK (added few days ago).
The documentation is on the way, however in the zip file you can find a simple example.
For example to perform a signup:
//set the BaasBox parameters: these operations initialize the SDK
BaasBox.setEndPoint("http://localhost:9000"); //this is the address of your BaasBox instance
BaasBox.appcode = "1234567890"; //this is your instance AppCode
//register a new user
BaasBox.createUser("user", "pass", function (res, error) {
if (res) console.log("res is ", res);
else console.log("err is ", error);
});
Now you can login into BaasBox
//perform a login
$("#login").click(function() {
BaasBox.login("user", "pass", function (res, error) {
if (res) {
console.log("res is ", res);
//login ok, do something here.....
} else {
console.log("err is ", error);
//login ko, do something else here....
}
});
Once the user is logged in he can load the Documents belonging to a Collection (the SDK automatically manages the Session Token for you):
BaasBox.loadCollection("catalogue", function (res, error) { //catalogue is the name of the Collection
if (res) {
$.each (res, function (i, item) {
console.log("item " + item.id); //.id is a field of the Document
});
} else {
console.log("error: " + error);
}
});
However under the hood the SDK uses JQuery. So you can inspect it to know how to user $.ajax to call BaasBox.
For example the creatUser() method (signup) is:
createUser: function (user, pass, cb) {
var url = BaasBox.endPoint + '/user'
var req = $.ajax({
url: url,
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({
username: user,
password: pass
}),
success: function (res) {
var roles = [];
$(res.data.user.roles).each(function(idx,r){
roles.push(r.name);
})
setCurrentUser({"username" : res.data.user.name,
"token" : res.data['X-BB-SESSION'],
"roles": roles});
var u = getCurrentUser()
cb(u,null);
},
error: function (e) {
cb(null,JSON.parse(e.responseText))
}
});
}