Personify Data Services allows us to download files through “FileDownload” Service Operation. The “SvcClient” code (provided in previous sections) is modified to provide a helper method invoke the service operation.
All configuration settings required for config.xml to enable FileDownload feature are the same as the ones mentioned for FileUpload (in previous sections).
The following configuration files have to be modified in order to support FileUpload as discussed below:
The following needs to be available/configured (double check to see if the following were already configured as part of FileUpload feature configuration):
<httpRuntime maxUrlLength="1024" relaxedUrlToFileSystemMapping="true" requestPathInvalidCharacters="" maxRequestLength="4194304"/>
And also the following:
<services>
<service name="PersonifyDataServices.PersonifyData">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="higherMessageSize" contract="System.Data.Services.IRequestHandler"/>
</service>
</services>
<webHttpBinding>
<binding name="higherMessageSize" maxBufferSize="4194304" maxBufferPoolSize="4194304" maxReceivedMessageSize="4194304" transferMode="Streamed">
<readerQuotas maxDepth="32" maxStringContentLength="4194304" maxArrayLength="4194304" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
</binding>
</webHttpBinding>
Using SvcClient.cs, we can download a file by calling “FileDownload” method as shown in the following example:
public void FileDownloadTest()
{
// Download existing customer image
var downloadStream = SvcClient.FileDownload("CustomerImages",
"WASHINGTON-0", null);
var emptyStream = downloadStream.ReadByte() < 1;
Assert.IsFalse(emptyStream);
// // Try to download image for customer with no image set
// downloadStream = SvcClient.FileDownload("CustomerImages", "JEFFERSON-0",
null);
// emptyStream = downloadStream.ReadByte() < 1;
// Assert.IsTrue(emptyStream);
//
// // Download existing customer related document
// downloadStream = SvcClient.FileDownload("CusDocs", "u157_normal.jpg",
"WASHINGTON-0");
// emptyStream = downloadStream.ReadByte() < 1;
// Assert.IsFalse(emptyStream);
//
// // Download existing customer related document
// downloadStream = SvcClient.FileDownload("DCDFiles", "Test2.doc",
"112493");
// emptyStream = downloadStream.ReadByte() < 1;
// Assert.IsFalse(emptyStream);
// // Try to download file which is not exists
// downloadStream = SvcClient.FileDownload("CommitteeMinutes",
"u157_normal.jpg", "WASHINGTON-0");
// emptyStream = downloadStream.ReadByte() < 1;
// Assert.IsTrue(emptyStream);
}
You can get more code samples from Personify Web Controls which use the “FileDownload” feature (like Profile.AttachmentsControl, PhotoControl, DigitalContentAccessControl, etc.).