Customer parameter are not going through for file delete - javascript

I have setup to directly upload image to s3 bucket and I am using fine uploader for that.
I am trying to send filename as parameter (to end point) while deleting a file.
Given below is callback snippet .
onDelete: function(id) {
$(this).setDeleteFileParams({ filename: this.getName(id) });
}
It is working fine for newly uploaded files, but I already have files through initialList (Option) and when I try to delete them the filename param is not going through.

You are not using the jQuery wrapper correctly. This is one of many reasons why I have suggested avoiding jQuery and the jQuery wrapper, as the "vanilla" API is much more intuitive. You've left out some code, but it looks like you are actually declaring your event handler as a property of the callbacks config object, which means you can avoid the jQuery wrapper entirely.
onDelete: function(id) {
var name = this.getName(id);
this.setDeleteFileParams({filename: name}, id);
}
But this code is not necessary, as Fine Uploader S3 sends the name of the object in S3 as a "key" parameter with the delete request.

Related

Getting a file URL from Sanity out of a blocks array

I'm building a website using Next JS and Sanity for the CMS. Sanity has built-in schemas for images but not for video, so a video needs to be uploaded with the File schema. The docs suggest that to get a file URL to be used on the front-end you should use the query language GROQ to make this conversion at the request like so:
// GROQ query
*[_type == 'movie'] {
title,
"manuscriptURL": manuscript.asset->url
}
But since I am using the File schema to embed short auto-looping videos into rich text content using the Blocks schema, I don't have the luxury of converting URLs at the request and need to do it dynamically as the blocks array data is being parsed for the #portabletext/react component.
Basically, what I get back for the file is simply an asset reference with the following data:
{
"_type": "file",
"asset": {
"_ref": "file-e4e61f3b231cca8e3339e96e050aee428009c777-gif",
"_type": "reference"
}
}
When I then use Sanity's own #sanity/asset-utils package to get a file URL using their buildFileUrl() function, I get a URL that is undefined for that asset where PROJECT_ID and DATASET are the correct values:
https://cdn.sanity.io/files/[PROJECT_ID]/[DATASET]/undefined.undefined
Here is the function I made, using their package's file URL function, to get the asset URL, which returns the URL above with the undefined values:
export function getSanityFileUrl(sanityFile) {
const fileUrl = buildFileUrl(sanityFile.asset, {projectId: sanityConfig.projectId, dataset: sanityConfig.dataset})
console.log(fileUrl)
}
Thanks and anything helps!
I found the solution. The buildFileUrl() function exported by #sanity/asset-utils expects a different asset object. Instead, a user in this situation should use the getFileAsset() function which can accept a reference to the file.

Resolve a 301 redirect and store the url for future use javascript

So I have a script that organises an un-formatted csv file and presents an output.
One of the pieces of data I receive in this data that we must return is a link to an image stored on Google Drive. The problem with this is Google Drive doesn't like to present you with a direct link to a file.
You can get the ID of a file (e.g. abc123DEFz) and view it online at https://drive.google.com/open?id=abc123DEFz. We need a direct link for another service to be able to process the file, not a redirect or some fancy website.
After poking around I discovered that https://drive.google.com/uc?export=view&id=abc123DEFz would redirect you directly to the file, and was what I somehow had to obtain inside the script.
The url it gave me though didn't really seem to have any relation to the ID and I couldn't just go ahead and swap the ID, for each file I would have to resolve this uc?export link into this link that would send me directly to the file. (Where the redirect sent me: http://doc-0c-2s-docs.googleusercontent.com/docs/securesc/32-char-long-alphanumeric-thing/another-32-char-long-alphanumeric-thing/1234567891234/12345678901234567890/12345678901234567890/abc123DEFz?e=view&authuser=0&nonce=abcdefgh12345&user=12345678901234567890&hash=32-char-long-alphanumeric-hash)
No authentication is required to access the file, it is public.
My script works like this:
const csv = require('csv-parser'),
fs = require('fs'),
request = require('request');
let final = [],
spuSet = [];
fs.createReadStream('data.csv')
.pipe(csv())
.on('data', (row) => {
>> data processing stuff, very boring so you don't care
console.log(`
I'm now going to save this information and tell you about the row I'm processing
so you can see why something went wrong`);
final.push(`[{"yes":"there is something here"},{"anditinvolves":${thatDataIJustGot}]`);
spuSet.push(`[{"morethings":123}]`);
})
.on('end', () => {
console.log('CSV file successfully processed');
console.log(`
COMPLETED! Check the output below and verify:
[${String(final).replace(/\r?\n|\r/g, " ")}]
COMPLETED! Check the output below and verify:
[${String(spuSet).replace(/\r?\n|\r/g, " ")}]`);
>> some more boring stuff where I upload the data somewhere and create a file containing said data
});
I tried using requests but it's a function with a callback so using the data outside of the function would be difficult, and wrapping everything inside the function would remove my ability to push to the array.
The url I get from the redirect would be included in the data I am pushing to the array for me to use later on.
I'm pretty bad at explaining crap, if you have any questions please ask.
Thanks in advance for any help you can give.
Try using the webContentLink parameter of the Get API call:
var webLink = drive.files.get({
fileId: 'fileid',
fields: 'webContentLink'
});
This will return the object:
{
"webContentLink": "https://drive.google.com/a/google.com/uc?id=fileId&export=download"
}
Then you can use split() to remove &export=download from the link, as we don't want to download it.
As fileId, you can get the Ids of your files by using the List API Call, and then you can loop through the list array calling the files.get from the first step.
My apologies if I misunderstood your issue.
In case you need help with the authentication to the Google Services, you can take a look at the Quickstart

fineuploader how to override the provided UUID

We're trying to pass an unique ID into Fineuploader (4.2.2, JQUERY) and reuse that into the fineuploader.js to set the foldername of where the upload is stored.
We basicly found two option:
Set the request option uuidName, which should be a string. Passing this one will result in "null" in console and doesn't do the trick.
Create a params request option where we define a variable with a value.
Option 2 get passed though we've got no idea how we get this value and process it into fineuploader.js (and alter the qq.getUniqueId-function with this new var for example).
Anyone know how we can get this done?
Thanks so much!
EDIT:
Underneath the code which initiates the uploader, how do I get the fileID inside the fineuploader.js?
$(".fine-uploader").fineUploader({
request: {
endpoint: 'server/endpoint',
params: {
fileID: '12345'
}
}
If you would like to override the UUID Fine Uploader creates for a file, you can do so either by passing your new UUID client-side via the setUuid method, or your server can return a newUuid property with its value set to the new UUID in its JSON response.

Get dynamic value to plugin options after the dom load. (Fineuploader plugin)

I am hoping for your help on this one.
I am using Fineuploader and I need to get and send input field value (that will be file group title).
For that I am using path to server side script (I didn't code it thats why I have to do it on my side, somehow):
endpoint: '/Services/hndFileUploader.ashx?case=deals&dealfiletitle=' + $("input").val()
Problem is that DOM with Fineuploader is already loaded and value of input is of course empty.
How can I get dynamic value to send with that query?
Thank you.
You do this using the setParams option for fineuploader. Docs are here, but basically it could be something like:
$('#fineUploaderElementId').fineUploader({
request: {
endpoint: '/Services/hndFileUploader.ashx'
}
}).on('submit', function(event, id, filename) {
$(this).fineUploader('setParams', {'case': 'deals', 'dealfiletitle': $(input).val(); });
});

plupload - send another request parameter with uploaded file

plupload creates nice ids in file object. How this id can be sent to the upload script?
The upload script has 3 variables in $_POST - file name, chunk number and total number of chunks.
How to add another parameter to plupload's POST request (in my case, the file.id)?
The first step would be to add a handler to the BeforeUpload event.
Then, if you are using multipart, you can change the uploader settings to dynamically set different multipart params:
plupload_instance.bind('BeforeUpload', function (up, file) {
up.settings.multipart_params = {fileid: file.id}
});
(warning: this example overrides any and all multipart_params, you can play it smarter than that by just setting fileid)
if you are not using multipart, your only options would be to pass the argument as a header, or to manually add the param to the URL for each file (these 2 options should also be done within BeforeUpload).
Note that when not using multipart, plupload will add the name and chunk params to the URL after any URL you already set for the uploader, for each file, so this is where extra params go.

Categories