How do I delete file that I have uploaded on Cloudinary using Jquery? - cloudinary

Can someone advise me how to delete a file in Cloudinary using Jquery?
I can't find any sample snippets to get started.

There good documentation on deleting client side uploaded images.
There are a few caveats to note though:
This does not work with unsigned uploads.
You will have to set return_delete_token: 1 in the options during your file upload, then pass the returned image's delete_token to the cloudinary.delete_by_token(delete_token) method.
From the documentation, you can do this over REST like so: curl https://api.cloudinary.com/v1_1/demo/delete_by_token -X POST --data 'token=delete_token'

Deleting resources requires an authenticated API (including a signature). Since the signature is based on your account's api_secret which shouldn't be included in your client-side code, you'll need to generate the signature on the server-side.
Having said that, when uploading you can set the new return_delete_token to true to tell Cloudinary to return a deletion token as part of the upload response.
The token can be used to delete the uploaded image within 10 minutes using an unauthenticated API request.
This is done with the delete_by_token method. See the following for a reference:
https://github.com/cloudinary/cloudinary_js/blob/47cf97a07f063a32311ff7d7cd09dc5a5a919318/js/jquery.cloudinary.js#L598

Related

How to upload images to AWS S3 with Ckeditor5

I am trying to upload an image to s3 bucket from CkEditor5. My front-end is built on vue and backend is on NodeJs. The uploading of images is working as expected as i can see the image is being saved to s3 bucket correctly. However I am having a confusion whether the bucket should be public or not ?
How CkEditor behaves to image uploading?
The ckEditor uses a simple upload adapter which uses its own built-in adapater that enables image uploading feature. When an images is dropped/copy-pasted to the ckEditor, it makes an http POST request to my backend NodeJs server and server in turns makes a call to S3 to upload that image(till this point everything is working as expected).
Now in order to embed an image inside CkEditor5, the server should respond with an URL attribute as JSON response like following so that CkEditor can fetch it and display inside editor.
{
url: url-path-of-image //full path of image in s3 bucket
}
This is where I am confused and need some pointers.
Question 1:
Should I make it public ? If yes, then what do I do about security, making it public will give access to anybody.
If I make it accessible with key/secret, how do I do it ?
Question 2:
This one is related to question#1
If I make it public then question#2 will not be an issue.However if I am not allowed to make it public in that case how would i display the images in normal div element ? Later on I need to display the content of CkEditor inside a div, with html parsing meaning inside a v-html attribute.
Any suggestions or pointers would be much helpful. Really appreciate taking time to read through the question.
I am not sure I am looking for the solutions. I can tell that it is related to signed urls in AWS S3. You keep bucket private, upload image to S3 and generate a signed url whenever you need to display the image to user on frontend.
If you learn more into the correct implementation please let me know.

Getting file diff with Github API

net project for which I need to detect and parse changes made to a specific single text file in a repository between different pull requests.
I've been successfully able to access the pull requests and the commits using the Github API but I don't know how to retrieve the lines that changed in the last commit?
Is this possible using the API? What would be the best approach?
If not should I try to read the last two file versions and implement a differ algorithm locally?
Thanks!
A pull request contains a diff_url entry like
"diff_url": "https://github.com/octocat/Hello-World/pull/1347.diff"
You can do this for any commit. For example, to get the diff of commit 7fd1a60b01f91b3 on octocat's Hello-World it's https://github.com/octocat/Hello-World/commit/7fd1a60b01f91b314f59955a4e4d4e80d8edf11d.diff.
This also works for branches. Here's master on octocat's Hello-World. https://github.com/octocat/Hello-World/commit/master.diff.
The general form is:
https://github.com/<owner>/<repo>/commit/<commit>.diff
For private repositories:
curl -H "Accept: application/vnd.github.v3.diff" https://<personal access token>:x-oauth-basic#api.github.com/repos/<org>/<repo>/pulls/<pull request>
Also works with the normal cURL -u parameter.
See: https://docs.github.com/en/rest/reference/pulls#get-a-pull-request
The crux is in the requested media type. You can pass the Accept header with value
application/vnd.github.diff
see documentation. For full reference, a GET request with the above and Authorization header to https://api.github.com/repos/{orgName}/{repoName}/pulls/{prId} does the trick.

Google Spreadsheet API: Post request fails

I have a Google spreadsheet published to the web, and I'm trying to read and write list-based feeds. I have not authenticated.
I can read data using a GET request just fine.
curl https://spreadsheets.google.com/feeds/list/1WngGKZHauwBqRxgC5E6DFMiJ-J8BDsadfwerF4RE0M/1/public/full
However, all my post requests to write data come back with an error
curl --data '' https://spreadsheets.google.com/feeds/list/1WngGKZHauwBqRxgC5E6DFMiJ-J8BDlN3mMaBfF4RE0M/1/public/full
curl --data '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gsx="http://schemas.google.com/spreadsheets/2006/extended"><gsx:id>1</gsx:id><gsx:status>1</gsx:status><gsx:user_email>1</gsx:user_email><gsx:url domain>1</gsx:url domain><gsx:highlighted_text>1</gsx:highlighted_text><gsx:complete_text comments>1</gsx:complete_text comments><gsx:created_date>1</gsx:created_date><gsx:updated_date>1</gsx:updated_date><gsx:created_by>1</gsx:created_by><gsx:updated_by>1</gsx:updated_by></entry>' https://spreadsheets.google.com/feeds/list/1WngGKZHauwBqRxgC5E6DFMiJ-J8BDlN3mMaBfF4RE0M/1/public/full
The error I'm getting is: "Sorry, the file you have requested does not exist. Please check the address and try again."
Do POST request require authentication? I can't find anything in the docs that say so.
Any help would be appreciated. Thanks.
Two things:
I think you need to use the private feed (.../private/full), not the public one (.../public/full) like you're using now. More on the private-versus-public distinction is in the API docs.
You will need an Authorization header. (That process gets pretty complicated, but there's a lot of good info here. Remember to select the appropriate scopes.)
Both are mentioned in the example about adding a list row in the Sheets API docs. (I'd link directly, but I don't have enough rep to add more than two links. Just search for "Adding a list row".)

FineUploader: Harvest original last modified date when uploading to Amazon S3

I would like to send the last modified date of the uploaded file to the server. I have the javascroipt snippet to get that using FileApi ($(this).fineUploaderS3('getFile', id).lastModifiedDate). I would like to send this information when the uploadSuccess's endPoint is called, but I cannot find the callback which is right for me at Events | Fine Uploader documentation, and I cannot find the way I could inject the data.
These are submitted as POST parameters to my server when the upload finished to S3: key, uuid, name, bucket. I would like to inject the lastModified date here somehow.
Option 2:
Asking the Amazon S3 service about last modification date does not help directly, because the uploaded file has the current date, not the file's original date. It would be great if we could inject the information into the FineUploader->S3 communication in a way that S3 would use it for setting it's own last modified date for the uploaded file.
Other perspective I considered:
If I use onSubmit and setParams then I the Amazon S3 server will take it as 'x-amz-meta-lastModified'. The problem is that when I upload larger files (which is uploaded in chunks with an other dance) then I get signing error. ...<Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>....
EDIT
The Other perspective I considered works. The bottleneck was the name of the custom metadata chih I used at setParams. It cannot contain capital letters, otherwise the signing fails. I did not find any reference documentation for it. For one I checked Object Key and Metadata - Amazon Simple Storage Service. If someone could find me a reference I would include that here.
The original question (when and how to send last modified date to the server component) remains.
(Server is PHP.)
EDIT2
The Option 2 will not work, as far my research went the "Last Modified" entry cannot be manually altered at Amazon S3.
If the S3 API does not return the expected last modified date, you can check the value of the lastModifiedDate on the File object associated with the upload (provided the browser supports the file API) and send that value as a parameter to the upload success endpoint. See the documentation for the setUploadSuccessParams API method for more details.

OAuth 1.0 binary data upload with RESTful api

I have a DESKTOP application which interacts with a web service through their RESTful api and OAuth 1.0. I can use all the resources fine, authentication, get/post calls to retrieve and send simple text data etc, no problems there.
However, I'm struggling to send binary data. The service allows sending pictures. For one part, they have a non-OAuth api through which you can also send a file in plain binary, simply pass some params in the URL and put the entire binary file in the post.
Now to do this through the OAuth api, becomes an issue:
The service specifies the post needs 2 parameters (not to be included in the URL since this is REST, but in the POST parameters):
image A binary file, base64 data, or a URL
type The type of file that's being sent in. Accepted values: file, base64, url
So we have 2 parameters: image contains the file itself, and type would be "file" to specify binary. But how am I supposed to include this through OAuth? given that the -image- and -type- parameters (and their values) must be used to generate the base string for the signature, which is matched against the parameters included in the POST.. I can't include the entire binary there as a value for the image parameter; so how is it done in this case?
nvm, their OAuth api expects the file as multipart/form-data with the variables there, and none in the base string for the signature (their non-OAuth api instead doesn't need multipart, so I expected their OAuth wouldn't either; their documentation is a bit lacking in this area).