Generate Public URL of Attachment expose to 3rd parties without authentication
internal final class TestClassV2
{
/// <summary>
/// Class entry point. The system will call this method when a designated menu
/// is selected or when execution starts and this class is set as the startup class.
/// </summary>
/// <param name = "_args">The specified arguments.</param>
public static void main(Args _args)
{
int64 _recId=22565437142; // refer to a record present in inventable eg released product
DocuRef docuRef;
EcoResProductImage ecoResProductImage;
// there can be multiple images against a product so we only creating url of image that is by default
select firstOnly docuRef
join ecoResProductImage
where ecoResProductImage.DefaultImage == NoYes::Yes
&& docuRef.RefRecId == _recid
&& docuRef.RefTableId == tableNum(InventTable);
if (docuRef.RecId)
{
str testUrl= File::SendFileToTempStore(
DocumentManagement::getAttachmentStream(docuRef),
ERDocuRef_Extension::filename(docuRef),
classstr(FileUploadTemporaryStorageStrategy),
true
);
info(testUrl);
}
else
{
throw error("Attachment not found for the provided RecId.");
}
}
}
//GET ANYTYPE OF ATTACHEMENT FROM DOCS
private void getAttachmentNote(InventTable inventTable)
{
DocuRef docuRef;
DocuType docuType;
str generatedUrl;
select firstOnly docuRef
order by docuRef.createddatetime desc
where docuRef.RefTableId == inventTable.TableId
&& docuRef.RefRecId == inventTable.RecId
&& docuRef.RefCompanyId == inventTable.DataAreaId
exists join DocuType
where DocuType.TypeId == 'DataSheet' // the DataSheet Can be changed to File or even docuRef.TypeId
&& DocuType.TypeGroup == DocuTypeGroup::Worksheet;
if (docuRef.RecId)
{
generatedUrl= File::SendFileToTempStore(
DocumentManagement::getAttachmentStream(docuRef),
ERDocuRef_Extension::filename(docuRef),
classstr(FileUploadTemporaryStorageStrategy),
true
);
}
}
Working Example
private List getAttachments(InventTable inventTable)
{
DocuRef docuRef;
DocuType docuType;
str generatedUrl;
List attachments = new List(Types::String);
while select docuRef
join docuType
where docuRef.RefTableId == inventTable.TableId
&& docuRef.RefRecId == inventTable.RecId
&& docuRef.RefCompanyId == inventTable.DataAreaId
&& docuRef.TypeId == 'DataSheet'
&& docuType.TypeGroup == DocuTypeGroup::Worksheet
{
if (docuRef.RecId)
{
generatedUrl= File::SendFileToTempStore(
DocumentManagement::getAttachmentStream(docuRef),
ERDocuRef_Extension::filename(docuRef),
classstr(FileUploadTemporaryStorageStrategy),
true );
attachments.addEnd(generatedUrl);
}
}
return attachments;
}
Author Anas
Comments
Post a Comment