PHP upload - "The file attribute value sent (Base64_encode of file) is not a valid Guid"
danielpastoor opened this issue · 3 comments
I can upload images to dataverse with base64_encode but not files to the file column.
Is there any example for this or is file upload not supported?
This is my code:
$issueImage = new Entity('cra35_incident_files');
$issueImage['cra35_incident_id'] = new EntityReference('incident', $incidentID);
$issueImage['cra35_name'] = $file->getClientOriginalName();
$imageRowID = $client->create($issueImage);
$issueImage = new \AlexaCRM\Xrm\Entity('cra35_incident_files', $imageRowID);
$issueImage['cra35_file'] = base64_encode(file_get_contents($file->path()));
$client->update($issueImage);
@danielpastoor image and file datatypes are definitely supported. Try upload method on OData client:
$client->getClient()->upload( 'cra35_incident_files', $incidentID, 'cra35_file', file_get_contents($file->path()), 'whateverthefilenameis' );
Don't think we have a sample handy but the above should work
Thank you for your quick response. Now my file upload works.
But now if I want to retrieve the file with this code:
$query = new \AlexaCRM\Xrm\Query\QueryByAttribute( 'cra35_incident_files' );
$query->AddAttributeValue( 'cra35_incident_id', '(Id)');
$query->ColumnSet = new \AlexaCRM\Xrm\ColumnSet( [ 'cra35_file'] );
$collection = $client->RetrieveMultiple( $query);
Then I only get the file ID is it possible to retrieve the base64 of the file
@danielpastoor as per https://docs.microsoft.com/en-us/powerapps/developer/data-platform/file-attributes, RetrieveMultiple cannot be used to retrieve a file column value. You need to access them on record-by-record basis.