Reputation: 51
I want to know the file id after upload. find it from file list, I think that isn't good idea and performance. so, How I can get the file id with good idea?
Thanks!
Upvotes: 4
Views: 1732
Reputation: 4316
For someone coming from .Net background, use:
string fileId = request.ResponseBody.Id;
To get download link also, remember to set
request. Fields = "id, webContentLink";
string fileId = request.ResponseBody.Id;
string downloadLink = request.ResponseBody.WebContentLink;
In order to get download link you will need to set shared permission to the uploaded file after uploading the file.
var permission = new Permission { AllowFileDiscovery = true, Type = "anyone", Role = "reader" };
await driveService.Permissions.Create(permission, request.ResponseBody.Id).ExecuteAsync();
Upvotes: 1
Reputation: 11
For example:
$file = new Google_Service_Drive_DriveFile();
$file->setName($fileTitle);
$result = $service->files->create(
$file,
array(
'data' => file_get_contents(FILE),
'mimeType' => 'application/octet-stream',
'uploadType' => 'multipart'
)
);
Var $result contain all information about uploaded file,so all you have to do is to display or use id.
echo 'Uploaded file id is '.$result['id'];
Upvotes: 1