字节集都获取到,然后做处理。没有做过研究。但如果是网页,跨域有问题这里简单合并下载。
[md]```html
let f = document.getElementsByTagName('input')[0]
f.addEventListener('change', function (e) {
let file = this.files[0]
let fileReader = new FileReader
fileReader.onload = function () {
let result = fileReader.result
console.log('')
console.log(result)
str2Ab('|| ...
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<input type="file" name="" id="">
<script>
let f = document.getElementsByTagName('input')[0]
f.addEventListener('change', function (e) {
let file = this.files[0]
let fileReader = new FileReader
fileReader.onload = function () {
let result = fileReader.result
console.log('[input-change]')
console.log(result)
str2Ab('|||||125.la', (result_str) => {
/* your code
到这里已经把字节集获取到了。
可以从EXIF入手。
这里简单的实现合并下载。
提交也是一样的道理。
当然肯定是会有跨域问题的。
*/
let change = mergeArrayBuffer(result,result_str)
download(change)
})
}
fileReader.readAsArrayBuffer(file)
})
//文本到ArrayBuffer
function str2Ab(str, callback) {
let blob = new Blob([str], { type: 'text/plain' })
let fileReader = new FileReader()
fileReader.onload = function () {
if (callback) {
callback.call(null, fileReader.result)
}
}
fileReader.readAsArrayBuffer(blob)
}
//合并
function mergeArrayBuffer(...arrays) {
let totalLen = 0
for (let i = 0; i < arrays.length; i++) {
arrays[i] = new Uint8Array(arrays[i]) //全部转成Uint8Array
totalLen += arrays[i].length
}
let res = new Uint8Array(totalLen)
let offset = 0
for (let arr of arrays) {
res.set(arr, offset)
offset += arr.length
}
return res.buffer
}
function download(buffer){
let url = URL.createObjectURL(new Blob([buffer],{type:'arraybuffer'}))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download','change.jpg')
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
</script>
</body>
</html>