I have a collection that has references to images, and when the user updates that collection with new images, I want to delete the old images. I am keeping references to the URL for the old images to pass into a function that is written in the cloud code.
I am running all of this local on my computer, however I get the same issue when I run this with the server running on Heroku. This is being called from the iOS SDK.
Here is the function in question:
Parse.Cloud.define('removeOldFilesFromDB', function (request, response) {
var fileUrls = request.params.fileUrls;
var promises = [];
for (var a = 0; a < fileUrls.length; a++) {
promises.push(Parse.Cloud.httpRequest({
method: 'DELETE',
url: fileUrls[a],
headers: {
'X-Parse-Application-Id': process.env.APP_ID || 'myAppId',
'X-Parse-Master-Key': process.env.MASTER_KEY || 'myMasterKey'
}
}));
}
Parse.Promise.when(promises).then( function (result) {
console.log("Successfully deleted files");
response.success(result);
}, function(a,b,c,d,e) {
console.log("Nope jacked it up!");
response.error("Error deleting files");
});
})
When I call the code in question, I don't even see the DELETE request in the parse-server logs at all.
I have the verbose: true flag set in my config, and this is the verbose output to the logs that I get when making this call from the client:
verbose: POST /parse/functions/removeOldFilesFromDB { host: 'e0ae0682.ngrok.io',
'x-parse-client-version': 'i1.12.0',
accept: '*/*',
'x-parse-session-token': 'r:5290c76c47678213770765d990ee38b6',
'x-parse-application-id': 'myAppId',
'x-parse-client-key': 'myClientKey',
'x-parse-installation-id': '3fafc219-1c63-4d68-b42f-5caa3e1c27cb',
'accept-language': 'en-us',
'accept-encoding': 'gzip, deflate',
'x-parse-os-version': '8.1 (12B411)',
'content-type': 'application/json; charset=utf-8',
'content-length': '204',
'user-agent': 'Spin%20the%20Bottle/1 CFNetwork/711.1.12 Darwin/14.0.0',
'x-parse-app-build-version': '1',
'x-parse-app-display-version': '1.0',
'x-forwarded-for': '71.163.238.223' } {
"fileUrls": [
"http://e0ae0682.ngrok.io/parse/files/myAppId/7b5b50e2871af27971be0425f367ab96_file.bin",
"http://e0ae0682.ngrok.io/parse/files/myAppId/cff909602b60b15331b1ac60a4f08697_file.bin"
]
}
Nope jacked it up!
verbose: error: code=141, message=Error deleting files
So it's odd that the DELETE call is not even showing up in there. Am I calling it wrong with the Parse.Cloud.httpRequest method or something?
If I hit the values for fileUrl in my browser, it downloads the images I'm trying to delete so the path is correct.
This is on the latest released version of parse-server, 2.2.10.
These were the instructions that I was following thinking that this is the correct way to do this:
https://parse.com/docs/rest/guide/#files-deleting-files
And this here to make the rest call from the cloud code:
https://parse.com/questions/making-a-rest-call-from-within-cloud-code
According to that, it says I can use Parse.Cloud.httpRequest to make REST calls, so I am not sure what you are referring to as that not the correct ways. Both of those have links to the docs and that is what I followed.
So I am obviously doing something wrong but I am not sure, anyone able to help out?
Just remove myAppId from file URL.
(e.g.)
from
http://e0ae0682.ngrok.io/parse/files/myAppId/7b5b50e2871af27971be0425f367ab96_file.bin
to
http://e0ae0682.ngrok.io/parse/files/7b5b50e2871af27971be0425f367ab96_file.bin
Related
So i'm posting a formdata object with axios to a node.js server. On iOS everything works perfectly, the data get posted and the image uploaded. But on android i'm getting this error
[AxiosError: Network Error]
here's my axios call
const handleSubmit = async (listing, { resetForm }) => {
const data = new FormData();
listing.images.forEach((image, index) =>
data.append("images", {
name: `product${Math.floor(Math.random() * 1000)}.`,
uri: image,
})
);
const res = await axios
.post("http://192.168.43.8:5000/products/addProduct", data, {
headers: {
"Content-Type": "multipart/form-data",
},
//tried adding this but didn't work out
transformRequest: (data) => data,
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
// handle error
});
}
}
Please note that on iOS it works without a problem.
here's a screenshot of the error when i used the react native debugger
if you use android emulator you need to change your ip to 10.0.2.2
change this:
http://192.168.43.8:5000/products/addProduct
to this:
http://10.0.2.2:5000/products/addProduct
By default http calls are blocked from android 9 version onwards, you either need to make your api calls HTTPS or you need to explicitly allow connection to this IP in your manifest file. Please refer this SO thread. How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?
For me i am getting axios error for my emulator and did not getting any error for ios simulator. The problem with my emulator is that it is not able to connect to Internet.
So I added google DNS server 8.8.8.8 (you can add any DNS server) for my mac and it worked.
I'm trying to upload an attachment i get from Outlook to a folder inside a SharePoint document library.
I am Following the docs:
https://learn.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http#http-request-to-upload-a-new-file
fetch(`https://graph.microsoft.com/v1.0/sites/${siteId}/drive/items/${parentId}:/${attachment.name}:/content`, {
method: 'PUT',
mode: 'cors',
headers: new Headers({
'Authorization': `Bearer ${accesToken}`,
'Content-Type': 'text/plain'
}),
body: attachment.contentBytes
})
All I get is an error with code: -1, Microsoft.SharePoint.Client.InvalidClientQueryException
I've tried setting the body of the fetch request as a simple string such as "hello world" with testing purposes and still get the same error.
Any ideas?
Thx in advance
[EDIT]
I suspect I'm not building the URL right.
I haven't found the documentation for the parameter:
{item-id} I'm assuming this ID is the folder's parentReference.siteId attribute.
Is that right?
Allright, so after some testing with the Microsoft Graph Explorer, I've found that the easiest way to upload a file to a SharePoint folder living inside a document library (distinct to the root document library) is to deal with it as a drive using the endpoint:
/drives/{drive-id}/items/{parent-id}:/{filename}:/content
(https://learn.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&tabs=http#http-request-to-upload-a-new-file)
In order to get the document library's drive-id, you can append to the graph query the odata parameter $expand=drive like:
`https://graph.microsoft.com/v1.0/sites/${siteId}/lists?$expand=drive`
Then, alongside other attributes of the targetted document library, you will find the "drive" object, which holds the drive-id associated to the document library you want to upload the file to. So, you would make the PUT request like:
fetch(`https://graph.microsoft.com/v1.0/drives/${libraryDriveId}/items/root:/${folderDisplayName}/${nameOfFile}:/content`, {
method: 'PUT',
mode: 'cors',
headers: new Headers({
'Authorization': `Bearer ${accesToken}`,
'Content-Type': 'text/plain'
}),
body: BINARY_STREAM_OF_DATA
}).then( (response) => {
if (!response.ok) return response.json().then((json) => {throw json});
return response.json();
}).then( (json) => {
//do whatever
}).catch( (err) => {
console.error(err);
})
libraryDriv
libraryDriveId comes from the https://graph.microsoft.com/v1.0/sites/${siteId}/lists?$expand=drive request
/root:/${folderDisplayName} means that the folder you are targetting inside the document library lives under "root:" (the root of the document library) followed by the displayName of the folder you want to upload the file to
nameOfFile is the name of the file you want to upload
I'm using axios to fetch data for my React Native app and I'm having an issue only for iOS. I am able to fetch data from my server perfectly fine, however if I change any data from my API, the changes doesn't reflect in iOS at all, only when I re-install the app then the changes will take place. I'm still not able to pinpoint what is causing the issue. This is only happening in iOS, Android works perfectly fine.
Fetch Data code:
axios.get('http://www.example.com/api')
.then((response) => {
// console.log(response);
this.setState({ data: response.data, loading: false });
});
Please let me know if I miss out any information.
If this has already been asked, I would greatly appreciate if you are able to point me in the right direction.
Thank you so much!
my guess is that the page is read from the cache and so you get an old copy.
what you need to do is to add a date stamp to the link, in order to force the app to load a 'fresh' page.
it goes something like that:
axios.get('http://www.example.com/api?dt='+(new Date()).getTime())
.then((response) => {
// console.log(response);
this.setState({ data: response.data, loading: false });
});
It can be resolved by adding headers: {'Cache-Control': 'no-cache'} to the header.
axios.get('http://www.example.com/api',
headers: {'Cache-Control': 'no-cache'})
.then((response) => {
// console.log(response);
this.setState({ data: response.data, loading: false });
});
I am currently using React Native 0.48 and react-native-image-crop-picker 0.16.
I'm attempting to take a file uri, and send it to a server using FormData and Fetch.
Here is a code snippet of what I am doing:
var image = await ImagePicker.openPicker({
width: 500,
height: 500,
cropping: true,
includeBase64: true,
});
var media = {
uri: image.path,
type: 'image/jpeg',
name: 'file.jpg',
};
var formData = new FormData();
formData.append("file", media);
fetch("https://requestb.in/1e6lgdo1", {
method: 'post',
headers: {
'Content-Type': 'multipart/form-data',
},
body: formData
}).then(function(r){
console.log("Success", r);
}).catch(function(e){
console.log("Error", e);
}).done();
Unfortunately when the request gets sent to the server instead of sending the file contents in the "file" form data field, it's just sending "[Object object]".
Depending on where you send the request to, that either results in the file contents becoming "[object Object]" or the request erring out.
I am unable to determine if this is a problem with my own code, or with react native itself. Any assistance would be greatly appreciated.
Update
I am using https://github.com/jpillora/uploader for my test server. (Note: Go doesn't ever use the notation [object Object] when stringifying an object, so I do not believe the problem lies with the server. In addition I saw this when uploading a file to S3 as well.)
An example of a request that ends up getting sent out is:
------WebKitFormBoundaryzt2jTR8Oh7dXB56z
Content-Disposition: form-data; name="file"
[object Object]
------WebKitFormBoundaryzt2jTR8Oh7dXB56z--
This problem had to do with another package React-Native Debugger hijacking fetch requests in order to allow for inspection in the debugger.
Complete information on the workaround can be found here: https://github.com/jhen0409/react-native-debugger/issues/101
I was able to successfully bypass it however by going back to the Google Chrome debugger.
I'm currently trying to call the twitter API using meteor and so far i got this:
updateTotalFoll:function(){
var Twit = Meteor.npmRequire('twit');
var T = new Twit({
consumer_key: 'AWzYAlWFRh9zsownZMg3',
consumer_secret: 'aYpL3zMPfqRgtX1usPQpEREEXVNPfNYna9FiIwTeDYR',
access_token: '4175010201-TEp9qNKO4mvjkj0GMjJFZIbGPYaVv4',
access_token_secret: 'EPpcJyN27E4PvhJpYaTHflNFOv3DuR05kTP2j'
});
var Id2=RandomCenas.findOne({api:"twitter"})._id;
T.get('statuses/user_timeline', { screen_name: 'jeknowledge' }, function (err, data, response){
//console.log(data[0].user.followers_count);
RandomCenas.update(Id2,{$set:{totalFoll:data[0].user.followers_count}});
});
}
with "RandomCenas" being a MongoDB.
What i'm trying to do is updating this collection with the info from the call , but i get this error
Error: Meteor code must always run within a Fiber.
Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
I've searched the web for a way to counter this , but i cant seem to apply the solutions that i came across with.
Any help with how i can deal with this?
try it like that
T.get('statuses/user_timeline', { screen_name: 'jeknowledge' }, Meteor.bindEnvironment(function (err, data, response) {
//console.log(data[0].user.followers_count);
RandomCenas.update(Id2,{$set:{totalFoll:data[0].user.followers_count}});
}));
the reason this is happening is because callback function which you pass it's happening outside the current Meteor's Fiber check the answer Error: Meteor code must always run within a Fiber