Friday, 27 November 2020
Wednesday, 25 November 2020
Tuesday, 24 November 2020
git create branch, merge branch
//create a new repository with new txt file in master
git add .git commit -m "1"
[master (root-commit) 9455543] 1
1 file changed, 1 insertion(+)
create mode 100644 New Text Document.txt
git remote add origin https://github.com/chuanshuoge6/test.git
git push -u origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 219 bytes | 219.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/chuanshuoge6/test.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
repository master has a txt with abc in it
//create a branch of master
git checkout -b branch1
Switched to a new branch 'branch1'
git push origin branch1
Total 0 (delta 0), reused 0 (delta 0)
remote:
remote: Create a pull request for 'branch1' on GitHub by visiting:
remote: https://github.com/chuanshuoge6/test/pull/new/branch1
remote:
To https://github.com/chuanshuoge6/test.git
* [new branch] branch1 -> branch1
branch1 created
branch1 has same file as master
//make change on branch1git add .
git commit -m "2"
[branch1 e32762d] 2
1 file changed, 2 insertions(+), 1 deletion(-)
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 251 bytes | 251.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/chuanshuoge6/test.git
9455543..e32762d branch1 -> branch1
Branch 'branch1' set up to track remote branch 'branch1' from 'origin'.
branch1 txt file is added a line "bcd"
//switch to mastergit checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
//merge branch1 to master
git merge branch1
Updating 9455543..e32762d
Fast-forward
New Text Document.txt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
git push
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/chuanshuoge6/test.git
9455543..e32762d master -> master
master is merged by branch1, master has a new line "bcd" from branch1
//delete branch1
git branch -d branch1
Deleted branch branch1 (was e86d57c).
git push origin :branch1
To https://github.com/chuanshuoge6/test.git
- [deleted] branch1
branch1 is removed
reference:Monday, 23 November 2020
golang 24 ionic react upload file to server 2 - upload multiple files in a click
code link: https://github.com/chuanshuoge6/go-ionic-directory
---------------------------------------
upload folder empty on server, click upload icon
select multiple files
files uploaded to server
verify on server upload folder
//cmd - server
index post
index post
upload post
Uploaded File: YodaoDict.exe File Size: 268352
Uploaded File: YodaoDict.exe.new File Size: 271936
Uploaded File: YoudaoDict.exe File Size: 5952064
Uploaded File: YoudaoDict.exe.old File Size: 5903936
index post
------------------------------
//go.main
func uploadPostHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("upload post")
w.Header().Set("Content-Type", "application/x-msdownload")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.WriteHeader(http.StatusCreated)
r.ParseMultipartForm(1000)
files := r.MultipartForm.File["myFile"]
dir := r.PostForm.Get("dir")
for i, header := range files {
file, err := files[i].Open()
if err != nil {
fmt.Println(err)
return
}
defer file.Close()
fmt.Printf("Uploaded File: %+v ", header.Filename)
fmt.Printf("File Size: %+v\n", header.Size)
path := dir + "\\" + header.Filename
resFile, err := os.Create(path)
if err != nil {
fmt.Println(err)
return
}
defer resFile.Close()
io.Copy(resFile, file)
}
json.NewEncoder(w).Encode("ok")
}
//folderDisplay.js
import React, { useState } from 'react';
import { folder, folderOpenOutline, documentOutline, cloudUploadOutline, cloudDownloadOutline } from 'ionicons/icons';
import { IonIcon } from '@ionic/react';
import axios from 'axios'
import '../pages/Home.css'
import saveAs from 'file-saver';
const qs = require('querystring')
export default function FolderDisplay(props) {
const [open, setOpen] = useState(false)
const [subDir, setSubDir] = useState([])
const [showLoad, setShowLoad] = useState(false)
const [downlaodProgress, setDownloadProgress] = useState(0)
const [uploadProgress, setUploadProgress] = useState(0)
function post_dir(d) {
axios({
method: 'post',
url: 'http://192.168.0.18:8000/',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: qs.stringify({ dir: d })
})
.then(response => {
setSubDir(response.data)
})
.catch(function (error) {
alert(error);
});
}
function download_dir(d, name) {
axios({
method: 'post',
url: 'http://192.168.0.18:8000/download/',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: qs.stringify({ dir: d }),
responseType: 'blob', // important
onDownloadProgress: progressEvent => {
const p = parseInt(progressEvent.loaded / props.size * 100);
setDownloadProgress(p)
},
})
.then(response => {
console.log(response)
saveAs(response.data, name);
})
.catch(function (error) {
alert(error);
});
}
function clickEvent() {
setShowLoad(!showLoad)
if (!props.isDir) { return }
if (!open) {
post_dir(props.dir)
}
setOpen(!open)
}
function downloadEvent() {
download_dir(props.dir, props.name)
}
function uploadEvent() {
const inputId = "fileInput" + props.dir
console.log(inputId)
document.getElementById(inputId).click()
}
function fileChange() {
const inputId = "fileInput" + props.dir
const files = document.getElementById(inputId).files
let i;
let formdata = new FormData();
for (i = 0; i < files.length; i++) {
formdata.append("myFile", files[i]);
}
formdata.append("dir", props.dir)
axios({
method: 'post',
url: 'http://192.168.0.18:8000/upload/',
data: formdata,
onUploadProgress: progressEvent => {
const p = parseInt(progressEvent.loaded / progressEvent.total * 99);
setUploadProgress(p)
},
})
.then(res => {
console.log(res.data);
if (res.data === 'ok') {
setUploadProgress(100)
}
})
.catch((err) => {
console.log(err)
})
}
const folder_icon = open ? <IonIcon icon={folderOpenOutline} /> : <IonIcon icon={folder} />
const sub_folder_list = subDir.map((item, index) => {
const dir_split = item.Name.split("\\")
const folder_name = dir_split[dir_split.length - 1].replace(props.name, '')
const dir_name = item.Name.replace(folder_name, '') + '\\' + folder_name
return <li key={dir_name}>
<FolderDisplay name={folder_name} dir={dir_name} isDir={item.IsDir} size={item.Size} key={item.Name} />
</li>
})
return (
<li >
<span onClick={() => clickEvent()}>
{props.isDir ? folder_icon : <IonIcon icon={documentOutline} />}{' '}
{props.name}{' '}
{showLoad && props.isDir ? <IonIcon icon={cloudUploadOutline} onClick={() => uploadEvent()} /> : null}{' '}
{showLoad && !props.isDir ? <IonIcon icon={cloudDownloadOutline} onClick={() => downloadEvent()} /> : null}{' '}
{downlaodProgress != 0 ? downlaodProgress + '%' : null}
{uploadProgress != 0 ? uploadProgress + '%' : null}
<input type="file" multiple id={"fileInput" + props.dir} style={{ display: "none" }} onChange={() => fileChange()}></input>
</span>
{open ? <ul className="no-bullets">
{sub_folder_list}
</ul> : null}
</li>
);
};
reference:
go handling multiple file uploads
Sunday, 22 November 2020
golang 23 ionic react upload file to server 1
code link: https://github.com/chuanshuoge6/go-ionic-directory
//main.go
app shows server directory on phone, static folder is empty
press upload icon
browse for files, select expo-location
upload starts
upload finishes
open static folder again, file is uploaded
upload another file
open folder on server, verify files are uploaded
//cmd - server logs
index get
index post
upload post
Uploaded File: expo-location-6a2380c18118466d88e1dbb510e776b9-signed.apk File Size: 51880840 MIME Header: map[Content-Disposition:[form-data; name="myFile"; filename="expo-location-6a2380c18118466d88e1dbb510e776b9-signed.apk"] Content-Type:[application/vnd.android.package-archive]]
index post
index post
upload post
request Content-Type isn't multipart/form-data
upload post
Uploaded File: expo-forex-771bec8df58843c3a1974f3d932afa85-signed.apk File Size: 53496647 MIME Header: map[Content-Disposition:[form-data; name="myFile"; filename="expo-forex-771bec8df58843c3a1974f3d932afa85-signed.apk"] Content-Type:[application/vnd.android.package-archive]]
index post
func uploadPostHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("upload post")
w.Header().Set("Content-Type", "application/x-msdownload")
w.Header().Set("Access-Control-Allow-Origin", "*")
w.WriteHeader(http.StatusCreated)
r.ParseMultipartForm(1000)
file, handler, err := r.FormFile("myFile")
if err != nil {
fmt.Println(err)
return
}
defer file.Close()
fmt.Printf("Uploaded File: %+v ", handler.Filename)
fmt.Printf("File Size: %+v ", handler.Size)
fmt.Printf("MIME Header: %+v\n", handler.Header)
path := rootDir() + "\\golang12\\static\\" + handler.Filename
resFile, err := os.Create(path)
if err != nil {
fmt.Println(err)
return
}
defer resFile.Close()
io.Copy(resFile, file)
json.NewEncoder(w).Encode("ok")
}
---------------------------
//folderDisplay.js
import React, { useState } from 'react';
import { folder, folderOpenOutline, documentOutline, cloudUploadOutline, cloudDownloadOutline } from 'ionicons/icons';
import { IonIcon } from '@ionic/react';
import axios from 'axios'
import '../pages/Home.css'
import saveAs from 'file-saver';
const qs = require('querystring')
export default function FolderDisplay(props) {
const [open, setOpen] = useState(false)
const [subDir, setSubDir] = useState([])
const [showLoad, setShowLoad] = useState(false)
const [downlaodProgress, setDownloadProgress] = useState(0)
const [uploadProgress, setUploadProgress] = useState(0)
function post_dir(d) {
axios({
method: 'post',
url: 'http://192.168.0.18:8000/',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: qs.stringify({ dir: d })
})
.then(response => {
setSubDir(response.data)
})
.catch(function (error) {
alert(error);
});
}
function download_dir(d, name) {
axios({
method: 'post',
url: 'http://192.168.0.18:8000/download/',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: qs.stringify({ dir: d }),
responseType: 'blob', // important
onDownloadProgress: progressEvent => {
const p = parseInt(progressEvent.loaded / props.size * 100);
setDownloadProgress(p)
},
})
.then(response => {
console.log(response)
saveAs(response.data, name);
})
.catch(function (error) {
alert(error);
});
}
function clickEvent() {
setShowLoad(!showLoad)
if (!props.isDir) { return }
if (!open) {
post_dir(props.dir)
}
setOpen(!open)
}
function downloadEvent() {
download_dir(props.dir, props.name)
}
function uploadEvent() {
const inputId = "fileInput" + props.dir
console.log(inputId)
//open file browser
document.getElementById(inputId).click()
}
function fileChange() {
const inputId = "fileInput" + props.dir
const file = document.getElementById(inputId).files[0]
let formdata = new FormData();
formdata.append("myFile", file);
axios({
method: 'post',
url: 'http://192.168.0.18:8000/upload/',
data: formdata,
onUploadProgress: progressEvent => {
const p = parseInt(progressEvent.loaded / progressEvent.total * 99);
setUploadProgress(p)
},
})
.then(res => {
console.log(res.data);
if (res.data === 'ok') {
setUploadProgress(100)
}
})
.catch((err) => {
console.log(err)
})
}
const folder_icon = open ? <IonIcon icon={folderOpenOutline} /> : <IonIcon icon={folder} />
const sub_folder_list = subDir.map((item, index) => {
const dir_split = item.Name.split("\\")
const folder_name = dir_split[dir_split.length - 1].replace(props.name, '')
const dir_name = item.Name.replace(folder_name, '') + '\\' + folder_name
return <li key={dir_name}>
<FolderDisplay name={folder_name} dir={dir_name} isDir={item.IsDir} size={item.Size} key={item.Name} />
</li>
})
return (
<li >
<span onClick={() => clickEvent()}>
{props.isDir ? folder_icon : <IonIcon icon={documentOutline} />}{' '}
{props.name}{' '}
{showLoad && props.isDir ? <IonIcon icon={cloudUploadOutline} onClick={() => uploadEvent()} /> : null}{' '}
{showLoad && !props.isDir ? <IonIcon icon={cloudDownloadOutline} onClick={() => downloadEvent()} /> : null}{' '}
{downlaodProgress != 0 ? downlaodProgress + '%' : null}
{uploadProgress != 0 ? uploadProgress + '%' : null}
<input type="file" id={"fileInput" + props.dir} style={{ display: "none" }} onChange={() => fileChange()}></input>
</span>
{open ? <ul className="no-bullets">
{sub_folder_list}
</ul> : null}
</li>
);
};
reference:
upload file to go server
go axios request Content-Type isn't multipart/form-data
axios upload download progress
Subscribe to:
Posts (Atom)