편집

다음을 통해 공유


Files and images overview

Dataverse provides several different ways to save binary data representing files in different types of columns. The following table summarizes some of the similarities and differences.

File Image Attachment & Note
Attribute Type File Image String
Create new columns? Yes. See Work with file column definitions using code Yes, See Work with image column definitions using code No, only activitymimeattachment.body and annotation.documentbody columns.
File Size limits Configurable by column MaxSizeInKB setting
Up to 10 GB, but client controls limited to 128 MB
Configurable by column MaxSizeInKB setting
Up to 30 MB.
Configurable by Organization.MaxUploadFileSize setting up to 128 MB. See File size limits
Upload Messages InitializeFileBlocksUpload
UploadBlock
CommitFileBlocksUpload
InitializeFileBlocksUpload
UploadBlock
CommitFileBlocksUpload
InitializeAttachmentBlocksUpload
UploadBlock
CommitAttachmentBlocksUpload
OR
InitializeAnnotationBlocksUpload
UploadBlock
CommitAnnotationBlocksUpload
Download Messages InitializeFileBlocksDownload
DownloadBlock
InitializeFileBlocksDownload
DownloadBlock
InitializeAttachmentBlocksDownload
DownloadBlock
OR
InitializeAnnotationBlocksDownload
DownloadBlock
Retrieve Behavior Can't retrieve file with record. Returns fileid value instead. Can retrieve thumbnail-sized images with records. Can retrieve file with records.
Set with Create No Only Primary image column Yes
Set with Update No, you must set the column value. Yes Yes
Delete File data Set column value to null or use DeleteFile message. Set column value to null. Set column value to null.
File types supported Any file not blocked by Organization.BlockedAttachments. See Block certain types of files Only gif, jpeg, tiff, bmp, & png files. Any file not blocked by Organization.BlockedAttachments. See Block certain types of files
Special Behaviors Column always creates and saves thumbnail-sized images. Full-sized images are saved only when the column is configured to do so. Special syntax required to download full-sized image files.

Each column has a companion string column that contains a relative URL to download the image.
More information Use file column data Use image column data Use file data with Attachment and Note records
Sample Code SDK for .NET
Web API
SDK for .NET
Web API
SDK for .NET
Web API

Block certain types of files

You can block the types of files that can be uploaded by the extension or MIME type.

Block files by extension

You can specify which types of files can't be saved in file columns, attachments and notes. Use the System Settings General tab under the Set blocked file extensions for attachments setting to control the file types to be blocked.

You can also query and modify this data programmatically. It's stored in the Organization.BlockedAttachments column. There's only one row in the organization table. You can use the SDK or Web API to query this data:

This static RetrieveBlockedAttachments method:

protected static string RetrieveBlockedAttachments(IOrganizationService service) {

   var query = new QueryExpression("organization")
   {
         ColumnSet = new ColumnSet("blockedattachments"),
         TopCount = 1
   };
   EntityCollection results = service.RetrieveMultiple(query);
   return (string)results.Entities.FirstOrDefault()["blockedattachments"];

}

Returns a string value like this by default:

ade;adp;app;asa;ashx;asmx;asp;bas;bat;cdx;cer;chm;class;cmd;com;config;cpl;crt;csh;dll;exe;fxp;hlp;hta;htr;htw;ida;idc;idq;inf;ins;isp;its;jar;js;jse;ksh;lnk;mad;maf;mag;mam;maq;mar;mas;mat;mau;mav;maw;mda;mdb;mde;mdt;mdw;mdz;msc;msh;msh1;msh1xml;msh2;msh2xml;mshxml;msi;msp;mst;ops;pcd;pif;prf;prg;printer;pst;reg;rem;scf;scr;sct;shb;shs;shtm;shtml;soap;stm;tmp;url;vb;vbe;vbs;vsmacros;vss;vst;vsw;ws;wsc;wsf;wsh;svg

More information: Build queries with QueryExpression

When anyone tries to upload a file using one of the blocked types, the following error occurs:

Name: AttachmentBlocked
Code: 0x80043e09
Number: -2147205623
Message: The attachment is either not a valid type or is too large. It cannot be uploaded or downloaded.

Block or allow certain MIME types

You can block or allow upload of files based on MIME types. More Information: Mime Type Validation.

You can also query and modify this data programmatically. It's stored in the Organization.BlockedMimeTypes and Organization.AllowedMimeTypes columns. There's only one row in the organization table. You can use the SDK or Web API to query this data:

public static (string, string) RetrieveMimeTypes(IOrganizationService service)
{
    var query = new QueryExpression("organization")
    {
        ColumnSet = new ColumnSet("blockedmimetypes", "allowedmimetypes"),
        TopCount = 1
    };
    EntityCollection results = service.RetrieveMultiple(query);
    Entity organization = results.Entities.FirstOrDefault();
    return (
        organization.Contains("blockedmimetypes") ? (string)organization["blockedmimetypes"] : string.Empty,
        organization.Contains("allowedmimetypes") ? (string)organization["allowedmimetypes"] : string.Empty);
}