File ID different from the URL File ID - Google Drive API - google-api

I'm trying to access a file in a Google Drive directory but linking to it using the File Id provided by the API it says that i don't have permission. What i saw is that the File Id in the URL is different from the one who returns from the API. Why?
Using the test page of the Google Api it returns a "Not Found" error(404) and not the "No Permissions" error. Anybody knows how to get this ID(same of the url) that links to the file instead of the File's ID
Edit: Found that the File Resource has a property called "webViewLink" is it the link to the file instead of using the ID?

When you are trying the Drive API, you can set using fields property what values you want to return from your call as it is shown in this image:
webViewLink will return you the link that's shown when you open the file in your browser.
id will return you the ID of the file.
I specified some values, but you can see HERE all the values you could use and if you put "*" you will return all of them. Also, I didn't show in the image the id of the file to not share that info.
HERE you can see why you are getting that error. Surely, you don't have enough permitions because you have already checked that it exists for what I understood in your question.

Related

The specified key does not exist - Laravel

I'm trying to create a temporary URL for a file in my application. I'm able to upload the file to S3 bucket and I'm able to use the method \Storage::temporaryUrl($this->url, now()->addHour(1)) generating the following URL
https://xxxxxx.s3.eu-west-2.amazonaws.com/https%3A//xxxxxxx.s3.eu-west-2.amazonaws.com/images/fYr20cgYh3nAwoEEQCOTaVTLLo7nRFrXjp7cYcCz.jpg?X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAVHH6TLEV3Z2FBWLY%2F20210622%2Feu-west-2%2Fs3%2Faws4_request&X-Amz-Date=20210622T191649Z&X-Amz-SignedHeaders=host&X-Amz-Expires=3600&X-Amz-Signature=6300aa81e69c6f4c96cb6f319a2b5ed2bfc2b2767138994928a49f3f93906745
When I click on this URL I get the following error:
The specified key does not exist.
From this question https://stackoverflow.com/a/28654035/4581336 I have checked the following:
the file name exists in my bucket and it is a copy-paste of the file under the Object URL in my bucket
I tried removing the extension from the file to see if it affects the URL but no luck as well. Having xxxx.jpg vs xxxxx as the file name is the same
I'm a fairly new guy in the AWS world so I will copy-paste things that I think might be important to help solve the issue.
The IAM user created has the following permissions:
AmazonS3FullAccess
The bucket Block Public Access settings for this account has everything blocked:
My bucket public permission has everything enabled as well:
I'm currently logged in as a root user (which therefore I'm assuming I can do whatever I want since I'm the root)
If I do all my buckets public I'm able to access the files using the extracted URL generated by the temporaryUrl method
The final goal
The objective of the bucket is to have a place to store files that are uploaded by users in my application. I don't want to have all the files public so I would like to restrict users to the files they own so I create a temporary URL with
Storage::disk('s3')->temporaryUrl($url, now()->addMinutes(30));
Since I'm fairly new to storing files in S3 my logic may be flawed. Please, correct me if this is not how it's supposed to go.
Questions I have looked at but didn't help me
Amazon S3 exception: "The specified key does not exist"
CloudFront + S3 Website: "The specified key does not exist" when an implicit index document should be displayed
aws-sdk: NoSuchKey: The specified key does not exist?
NoSuchKey: The specified key does not exist AWS S3 Codebuild
AWS::S3::NoSuchKey The specified key does not exist
In your first URL, it seems like you've got the hostname there twice - https://xxxxxx.s3.eu-west-2.amazonaws.com appears once, and then a second time encoded. Are you storing the full hostname in the $url parameter to temporaryUrl? You should only be passing the key (the actual filename) to that method.
The error doesn't sound like a permission error - it appears as though you have access to the bucket but just aren't getting the file path correct.

What is the format of a folder ID in Google Drive?

My question is similar to What is format of Google Drive's FileID ? I need to find out whether new File has been uploaded to my drive or not using API's but I want to know the format of a folder ID in Google Drive, the one that appears in the URL bar when you open a folder in your Google drive, the thing after https://drive.google.com/drive/u/0/folders/<this part>.
Google Drive folder id doesn't have a specific guaranteed format. This (apparent format which really isn't a format) has changed in the past and may change again.
Trying to create any kind of local verification of this will be futile.
The best option would be to do a Files: get and test if you get a response. This will work better as it will also verify that the user has access to the file as well as testing that its a valid file id format.
Any (regex) attempt to verify the file id wouldn't really verify it as its not going to test if the user has access.
A folder ID starts with a 1 followed by 32 base-64 encoded digits, except unlike base64 the + is replaced by - and / is replaced by _. You can use the following regex:
/^1[A-Za-z0-9-_]{32}$/

Magento REST API - "Specified request cannot be processed" Error [duplicate]

I'm running Magento 2.2.5 and was having trouble working out what the URL was for making API requests. For example to GET a list of countries I had seen the following syntax used:
/rest/default/V1/directory/countries
which has worked on some stores, but I was getting this error:
{
"message" : "Specified request cannot be processed.",
"trace" : null
}
I started playing around with the URL format and removed the "default" and used this instead:
/rest/V1/directory/countries
and the requests were then successful. How does one determine what the base URL to use for Magento REST API requests? I haven't been able to find this documented so far.
The syntax of Magento 2 Api is
http://<:host:>/rest/<:store_code:>/<:api_path:>
Here store_code can be any one of the "store view" of your Magento2 instance. You can get the store code in admin panel. You can use store_code to get information specific to that Store View via API. By default Magento2 installation comes with 1 website, 1 store & 1 store view (this store-view has code "default", in your case this might have changed hence you get the error).
The architecture can be understand with the help of image
Reference Image
Ref: https://docs.magento.com/m2/ce/user_guide/stores/websites-stores-views.html
When you specify store_code it checks information for that particular Store-View. If the specified store_code is not found in the database, Api returns "Specified request cannot be processed." message.
When you do not specify store_code it first finds default Website, then finds default Store for this Website & then finds default Store View Associated to this Store. And finally it returns information for this default Store-View. The association of default store & store-view can be changed from admin panel.
Reference Image
Hence the URL for API should be below in case you need store specific information. store_code can be set to all if you need information for all the stores.
http://<:host:>/rest/<:store_code:>/<:api_path:>

Google Drive API (REST) - Get download, files views and so on....?? (Is it possible??)

This is documentation which I'm using - https://developers.google.com/drive/api/v3/search-parameters
Does anyone know the way of getting through Google Drive API, the number of times the file was downloaded, views(ideal views by whom)...
I could not find any way of doing this.
Google drive files are denoted by a file resource this contains all the information that you have access to about the file. Only some of the information you are after is available
createdTime datetime The time at which the file was created (RFC 3339 date-time). writable
modifiedTime datetime The last time the file was modified by anyone (RFC 3339 date-time).
Note that setting modifiedTime will also update modifiedByMeTime for the user.
lastModifyingUser nested object The last user to modify the file.
You can see who last changed the file but you cant see who has seen the file or any information about how many times it was downloaded.

DocsList findFolder() issue

This is a google spreadsheet script question.
I have a GUI setup in order to search for "SouthWest" and then find a "test" sheet. This is the code I am using.
var file = DocsList.getFolder("SouthWest").find("test");
This works just fine when I run it under my account (as I have this folder and file setup correctly) but when another user is logged into google docs it will attempt to search for this folder/file under the new user instead of the owner of the document. Is there a way to have it just search the DocsList of the owner of the spreadsheet that is currently open? The error that I get under the new user is "Error encountered: Cannot find folder SouthWest." Thanks.
If you always want to access the same file, you can use the getFileById method and address it directly instead of searching every time:
https://developers.google.com/apps-script/class_docslist#getFileById
Of course, you should make sure that all users are allowed to access that file.

Resources