Skip to content

Commit 0628dee

Browse files
committed
fix: 🐛 direct file upload from dropzone
1 parent a7454f1 commit 0628dee

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

src/Shell.tsx

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,35 @@ class ShellContainer extends React.Component<Props, State> implements ShellFunct
162162
clearTimeout(this.addFileTimeout)
163163
this.addFileTimeout = setTimeout(() => {
164164
console.log('addFile timeout')
165+
166+
if(true || location.hash.includes('#feedbot-direct-upload')) {
167+
const attachmentUrl = this.props.attachmentUrl
168+
const f = file
169+
const reader = new FileReader()
170+
171+
console.log(f)
172+
173+
reader.onload = (function(file) {
174+
return async function(e: any) {
175+
console.log(e)
176+
var binaryData = e.target.result
177+
//Converting Binary Data to base 64
178+
var base64String = 'data:' + file.type + ';base64,' + window.btoa(binaryData)
179+
const body = JSON.stringify([{data: base64String, fileName: file.name}])
180+
try{
181+
const response = await fetch(attachmentUrl, {
182+
method: 'POST',
183+
body
184+
})
185+
186+
console.log("File successfully uploaded", response.status, response.statusText)
187+
} catch(error) {
188+
console.log("File upload failed", error)
189+
}
190+
}})(f)
191+
192+
reader.readAsBinaryString(f)
193+
}
165194
this.props.sendFiles([file], true || location.hash.includes('#feedbot-direct-upload'))
166195
}, 75)
167196
}
@@ -208,17 +237,18 @@ class ShellContainer extends React.Component<Props, State> implements ShellFunct
208237
return (
209238
<div className={className}>
210239
{
211-
this.props.showUploadButton &&
212-
<label
213-
className="wc-upload"
214-
htmlFor="wc-upload-input"
215-
onKeyPress={evt => this.handleUploadButtonKeyPress(evt)}
216-
tabIndex={0}
217-
>
218-
<svg>
219-
<path d="M19.96 4.79m-2 0a2 2 0 0 1 4 0 2 2 0 0 1-4 0zM8.32 4.19L2.5 15.53 22.45 15.53 17.46 8.56 14.42 11.18 8.32 4.19ZM1.04 1L1.04 17 24.96 17 24.96 1 1.04 1ZM1.03 0L24.96 0C25.54 0 26 0.45 26 0.99L26 17.01C26 17.55 25.53 18 24.96 18L1.03 18C0.46 18 0 17.55 0 17.01L0 0.99C0 0.45 0.47 0 1.03 0Z" />
220-
</svg>
221-
</label>
240+
// FEEDYOU - do not show default upload button
241+
// this.props.showUploadButton &&
242+
// <label
243+
// className="wc-upload"
244+
// htmlFor="wc-upload-input"
245+
// onKeyPress={evt => this.handleUploadButtonKeyPress(evt)}
246+
// tabIndex={0}
247+
// >
248+
// <svg>
249+
// <path d="M19.96 4.79m-2 0a2 2 0 0 1 4 0 2 2 0 0 1-4 0zM8.32 4.19L2.5 15.53 22.45 15.53 17.46 8.56 14.42 11.18 8.32 4.19ZM1.04 1L1.04 17 24.96 17 24.96 1 1.04 1ZM1.03 0L24.96 0C25.54 0 26 0.45 26 0.99L26 17.01C26 17.55 25.53 18 24.96 18L1.03 18C0.46 18 0 17.55 0 17.01L0 0.99C0 0.45 0.47 0 1.03 0Z" />
250+
// </svg>
251+
// </label>
222252
}
223253
{
224254
this.props.showUploadButton &&

0 commit comments

Comments
 (0)