
Visualforce:
<apex:form id="techForm" enctype="multipart/form-data">
<apex:actionFunction name="fillAttachment" action="{!formController.FillAttachment}" reRender="attachmentsBlock">
<apex:param assignTo="{!formController.handleFileContent}" name="handleFileContent" value="" />
</apex:actionFunction>
<script type="text/javascript">
function check_extension(filename) {
var files = document.getElementById('attachment').files;
var file = files[0];
fillAttachment(file);
}
</script>
<input type="file" accept=".gif, .jpg, .jpeg, .tif, .tiff, .png, .pdf" onChange="check_extension(this.value)" class="hidden" value="" filename="attachment" id="attachment" />
</form>
Apex Class:
The problem of this approach is that in this way, i got „Regex too complicated“ error.public class ContactUsController {
public List<Attachment> attachments { get; set; }
public String handleFileContent { get; set; }
public void FillAttachment() {
if(this.handleFileContent != null && this.handleFileContent.length() > 0) {
Attachment toAttach = new Attachment(body = Blob.valueOf(this.handleFileContent));
this.attachments.add(toAttach);
}
}
}
- So, I tried to check heap size (http://blog.jeffdouglas.com/2010/08/16/managing-the-heap-in-salesforce-com/), but it is no problem.
- I also tryied to use Transcient method, but it does not work (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_transient.htm).
- Finnaly I tried to use future method, but it is static, so it is not possible for me to use it (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_invoking_future_methods.htm).
I suggest that problem is that I exceed limit of view stat (https://developer.salesforce.com/forums/?id=906F0000000AsUHIA0) Can you help me? To Sum Up. Is there any way, how to send file from visualforce page using javascript and actionfunction to apex class? I can not use apex:imputFile because I have to use more rerender scopes on that page. I hope that there will be some workaround. (I thinking about iframe page using apex:imputFile embedded to my page which handle uploading attachments and then via timpestamp-identifiers map it to relevant Case. But I think that it is "weird" way to upload files.) Thank you for your answer.Martin