A rough markup of this component using input type file component. Please refer the previous article to get an idea of how the helper JS and the apex class is formed.
<div class="slds-form-element">
<span class="slds-form-element__label" id="file-selector-id">Attachment</span>
<div class="slds-form-element__control">
<div class="slds-file-selector slds-file-selector_files">
<div class="slds-file-selector__dropzone">
<input type="file" class="slds-file-selector__input slds-assistive-text" accept="image/png" id="file-upload-input-01" aria-describedby="file-selector-id" aura:id="file" onchange="{!c.showfile}"/>
<label class="slds-file-selector__body" for="file-upload-input-01">
<span class="slds-file-selector__button slds-button slds-button_neutral">
<c:svgIcon class="slds-button__icon slds-button__icon_left" xlinkHref="/resource/slds232/assets/icons/utility-sprite/svg/symbols.svg#upload" />
Upload Files
</span>
<span class="slds-file-selector__text slds-medium-show">or Drop Files</span>
</label>
</div>
</div>
</div>
</div>
showfile:function(component,event,helper){
helper.show(component,event);
var f = event.target.files[0];
var fileInput = component.find("file").getElement();
var file = fileInput.files[0];
var reader = new FileReader();
reader.onloadend = function(e) {
var contents = e.target.result;
var base64Mark = 'base64,';
var dataStart = contents.indexOf(base64Mark) + base64Mark.length;
var fileContents = contents.substring(dataStart);
helper.upload(component, file, encodeURIComponent(fileContents), function(answer) {
if (answer) {
helper.hide(component,event);
}
else{
}
});
}
reader.readAsDataURL(file);
}
0 comments:
Post a Comment