Purpose:
Allow Lenders to use your integration to upload files from their local drive as an attachment to a new transaction. This method returns a URL and authorization token, which are to be used to stream the selected file as binary content to the EPC platform.
You don't have to use this!
If you want to design a custom file upload experience, this method may be useful to you. However, you can also leverage the host application's native file upload experience by utilizing the
application
objectsperformAction('getAvailableResources')
method.
Sample Usage:
import host from '@elliemae/em-ssf-guest'
...
// Assuming selectedResource is a standard File object
// which you have collected from a users file input...
async function createResource(selectedResource) {
try {
const transactionObject = await host.getObject('transaction')
// Step 1: Create an EPC resource
const resourceData = await transactionObject.createResource({name: selectedResource.name})
// Step 2: Stream the file to the resource location
const result = await fetch(resourceData.location, {
method: 'PUT',
headers: {
'Content-Type': selectedResource.type,
'Authorization': resourceData.authorizationHeader
},
body: selectedResource
})
// Upon success - commit the resource to the transaction request
applicationState.transactionRequest.resources.push({
id: resourceData.id,
name: resourceData.name,
mimeType: selectedResource.type
})
} catch (error) {
console.log({error})
}
}
import host from '@elliemae/em-ssf-guest'
...
// Assuming selectedResource is a standard File object
// which you have collected from a users file input...
host.getObject('transaction')
.then(
(transactionObject) => {
// Step 1: Create an EPC resource
transactionObject.createResource({
name: selectedResource.name
})
.then(
(resourceData) => {
// Step 2: Stream the file to the resource location
fetch(resourceData.location, {
method: 'PUT',
headers: {
'Content-Type': selectedResource.type,
'Authorization': resourceData.authorizationHeader
},
body: selectedResource
})
.then(() => {
// Upon success - commit the resource to the transaction request
applicationState.transactionRequest.resources.push({
id: resourceData.id,
name: resourceData.name,
mimeType: selectedResource.type
})
})
.catch(
(error) => {
console.log({error})
}
)
}
)
.catch(
(error) => {
console.log({error})
}
)
}
)
.catch(
(error) => {
console.log({error})
}
)
Interface:
Input:
Type: Object
{
name: 'RESOURCE_NAME'
}
Returns:
Type: Promise
==> Resolved:
{
id: 'RESOURCE_ID',
repository: 'urn:elli:skydrive',
name: 'RESOURCE_NAME',
location: 'STREAMING_URL',
authorizationHeader: 'STREAMING_AUTHORIZATION_HEADER'
}
==> Rejected:
An error is raised, containing a message attribute with details about the error that occurred
{
message: "{{ERROR_DETAILS}}"
}