Explore all File Sharing open source software, libraries, packages, source code, cloud functions and APIs.

Popular New Releases in File Sharing

ffsend

ffsend v0.2.72

projectsend

r1335

sharry

Sharry Nightly

iptux

v0.8.2

crocgui

update to croc v9.5.2

Popular Libraries in File Sharing

core

by owncloud doticonphpdoticon

star image 7725 doticonNOASSERTION

:cloud: ownCloud web server core (Files, DAV, etc.)

ffsend

by timvisee doticonrustdoticon

star image 5360 doticonGPL-3.0

:mailbox_with_mail: Easily and securely share files from the command line. A fully featured Firefox Send client.

sharedrop

by szimek doticonjavascriptdoticon

star image 4992 doticonMIT

Easy P2P file transfer powered by WebRTC - inspired by Apple AirDrop

sharedrop

by cowbell doticonjavascriptdoticon

star image 4563 doticonMIT

Easy P2P file transfer powered by WebRTC - inspired by Apple AirDrop

projectsend

by projectsend doticonphpdoticon

star image 834 doticonGPL-2.0

ProjectSend is a free, open source software that lets you share files with your clients, focused on ease of use and privacy. It supports clients groups, system users roles, statistics, multiple languages, detailed logs... and much more!

zget

by nils-werner doticonpythondoticon

star image 466 doticonMIT

Filename based peer to peer file transfer

sharry

by eikek doticonelmdoticon

star image 356 doticonGPL-3.0

Sharry is a self-hosted file sharing web application.

onedrivecmd

by cnbeining doticonpythondoticon

star image 344 doticonAGPL-3.0

A command line client for Onedrive.

iptux

by iptux-src doticonc++doticon

star image 344 doticonGPL-2.0

A software for sharing in LAN

Trending New libraries in File Sharing

warpinator

by linuxmint doticonpythondoticon

star image 337 doticonGPL-3.0

Share files across the LAN

skytransfer

by kamy22 doticontypescriptdoticon

star image 113 doticonMIT

Free, open-source, decentralized and encrypted filesharing.

crocgui

by howeyc doticongodoticon

star image 108 doticonISC

GUI for croc

DaFileShare

by deskangel doticonswiftdoticon

star image 66 doticonGPL-3.0

A file share app for macos

go-file

by songquanpeng doticongodoticon

star image 34 doticonMIT

基于 Go 的文件分享工具. File sharing tool written in Go.

InShare

by ShivamJoker doticoncssdoticon

star image 30 doticon

Simple file sharing web app with drag & drop

asfa

by obreitwi doticonrustdoticon

star image 21 doticonNOASSERTION

Avoid sending file attachments by uploading them via SSH to a remote site and sending a publicly-accessible URL with non-guessable (hash-based) prefix instead.

ipfs-pinner

by wabarc doticongodoticon

star image 20 doticonGPL-3.0

A toolkit helps upload files to IPFS pinning services.

secureshare

by alttch doticonpythondoticon

star image 17 doticonApache-2.0

secure file sharing personal server

Top Authors in File Sharing

1

YunoHost-Apps

3 Libraries

star icon27

2

mafintosh

2 Libraries

star icon39

3

owncloud

2 Libraries

star icon7732

4

benjaminalt

1 Libraries

star icon2

5

Azelphur

1 Libraries

star icon13

6

YashMeh

1 Libraries

star icon2

7

kamy22

1 Libraries

star icon113

8

LandonPowell

1 Libraries

star icon2

9

hughfm

1 Libraries

star icon5

10

derekeder

1 Libraries

star icon2

1

3 Libraries

star icon27

2

2 Libraries

star icon39

3

2 Libraries

star icon7732

4

1 Libraries

star icon2

5

1 Libraries

star icon13

6

1 Libraries

star icon2

7

1 Libraries

star icon113

8

1 Libraries

star icon2

9

1 Libraries

star icon5

10

1 Libraries

star icon2

Trending Kits in File Sharing

No Trending Kits are available at this moment for File Sharing

Trending Discussions on File Sharing

Command Line Arguments for Container in Kubernetes

How to build a Loki server Docker image using Docker-compose

Inter-process communication (C++ to C#) using Memory mapped file (IOException)

Is it possible to open a PDF file from a database-fetched Uri from Android API 28?

Docker failed to start on Windows 11

Should I use GridFS or some other method to create a file sharing app?

TCP transfer files without closing socket

WebRTC onicecandidate not getting called in cordova android, but is getting called in browser

How to disable static file serving with hunchentoot?

The torrent program was stopped by the DoS attack. I want to know the reason

QUESTION

Command Line Arguments for Container in Kubernetes

Asked 2022-Mar-12 at 02:46

I'm trying to deploy a docker container to my Kubernetes cluster, but I'm running into an issue with passing the required command-line arguments to the container. I need to pass two arguments called --provider local and --basedir /tmp. Here is what the docker run command looks like (I can run this without any issues on my docker host):

1docker run -d -p 8080:8080 --name transfer-sh -v /tmp:/tmp dutchcoders/transfer.sh:latest --provider local --basedir /tmp
2

However, when I apply the deployment YAML to my cluster the container fails with this error (I'm running kubectl apply -f deploy.yaml to apply my changes to the cluster):

Incorrect Usage. flag provided but not defined: -provider local

So my YAML specifies that the flag should be --provider, but for some reason I haven't been able to find yet the container only sees -provider which is indeed not a valid option. This is the full help message:

1docker run -d -p 8080:8080 --name transfer-sh -v /tmp:/tmp dutchcoders/transfer.sh:latest --provider local --basedir /tmp
2NAME:
3transfer.sh - transfer.sh
4
5DESCRIPTION:
6Easy file sharing from the command line
7
8USAGE:
9transfer.sh [flags] command [arguments...]
10
11COMMANDS:
12version
13help, h  Shows a list of commands or help for one command
14
15FLAGS:
16--listener value                     127.0.0.1:8080 (default: "127.0.0.1:8080") [$LISTENER]
17--profile-listener value             127.0.0.1:6060 [$PROFILE_LISTENER]
18--force-https                         [$FORCE_HTTPS]
19--tls-listener value                 127.0.0.1:8443 [$TLS_LISTENER]
20--tls-listener-only                   [$TLS_LISTENER_ONLY]
21--tls-cert-file value                 [$TLS_CERT_FILE]
22--tls-private-key value               [$TLS_PRIVATE_KEY]
23--temp-path value                    path to temp files (default: "/tmp") [$TEMP_PATH]
24--web-path value                     path to static web files [$WEB_PATH]
25--proxy-path value                   path prefix when service is run behind a proxy [$PROXY_PATH]
26--proxy-port value                   port of the proxy when the service is run behind a proxy [$PROXY_PORT]
27--email-contact value                email address to link in Contact Us (front end) [$EMAIL_CONTACT]
28--ga-key value                       key for google analytics (front end) [$GA_KEY]
29--uservoice-key value                key for user voice (front end) [$USERVOICE_KEY]
30--provider value                     s3|gdrive|local [$PROVIDER]
31--s3-endpoint value                   [$S3_ENDPOINT]
32--s3-region value                    (default: "eu-west-1") [$S3_REGION]
33--aws-access-key value                [$AWS_ACCESS_KEY]
34--aws-secret-key value                [$AWS_SECRET_KEY]
35--bucket value                        [$BUCKET]
36--s3-no-multipart                    Disables S3 Multipart Puts [$S3_NO_MULTIPART]
37--s3-path-style                      Forces path style URLs, required for Minio. [$S3_PATH_STYLE]
38--gdrive-client-json-filepath value   [$GDRIVE_CLIENT_JSON_FILEPATH]
39--gdrive-local-config-path value      [$GDRIVE_LOCAL_CONFIG_PATH]
40--gdrive-chunk-size value            (default: 16) [$GDRIVE_CHUNK_SIZE]
41--storj-access value                 Access for the project [$STORJ_ACCESS]
42--storj-bucket value                 Bucket to use within the project [$STORJ_BUCKET]
43--rate-limit value                   requests per minute (default: 0) [$RATE_LIMIT]
44--purge-days value                   number of days after uploads are purged automatically (default: 0) [$PURGE_DAYS]
45--purge-interval value               interval in hours to run the automatic purge for (default: 0) [$PURGE_INTERVAL]
46--max-upload-size value              max limit for upload, in kilobytes (default: 0) [$MAX_UPLOAD_SIZE]
47--lets-encrypt-hosts value           host1, host2 [$HOSTS]
48--log value                          /var/log/transfersh.log [$LOG]
49--basedir value                      path to storage [$BASEDIR]
50--clamav-host value                  clamav-host [$CLAMAV_HOST]
51--perform-clamav-prescan             perform-clamav-prescan [$PERFORM_CLAMAV_PRESCAN]
52--virustotal-key value               virustotal-key [$VIRUSTOTAL_KEY]
53--profiler                           enable profiling [$PROFILER]
54--http-auth-user value               user for http basic auth [$HTTP_AUTH_USER]
55--http-auth-pass value               pass for http basic auth [$HTTP_AUTH_PASS]
56--ip-whitelist value                 comma separated list of ips allowed to connect to the service [$IP_WHITELIST]
57--ip-blacklist value                 comma separated list of ips not allowed to connect to the service [$IP_BLACKLIST]
58--cors-domains value                 comma separated list of domains allowed for CORS requests [$CORS_DOMAINS]
59--random-token-length value          (default: 6) [$RANDOM_TOKEN_LENGTH]
60--help, -h                           show help
61

Here is the Docker Hub for the image I'm trying to deploy: dutchcoders/transfer.sh

Here is the GitHub: https://github.com/dutchcoders/transfer.sh

My cluster's version is 1.23.4 and the full deployment YAML is here:

1docker run -d -p 8080:8080 --name transfer-sh -v /tmp:/tmp dutchcoders/transfer.sh:latest --provider local --basedir /tmp
2NAME:
3transfer.sh - transfer.sh
4
5DESCRIPTION:
6Easy file sharing from the command line
7
8USAGE:
9transfer.sh [flags] command [arguments...]
10
11COMMANDS:
12version
13help, h  Shows a list of commands or help for one command
14
15FLAGS:
16--listener value                     127.0.0.1:8080 (default: "127.0.0.1:8080") [$LISTENER]
17--profile-listener value             127.0.0.1:6060 [$PROFILE_LISTENER]
18--force-https                         [$FORCE_HTTPS]
19--tls-listener value                 127.0.0.1:8443 [$TLS_LISTENER]
20--tls-listener-only                   [$TLS_LISTENER_ONLY]
21--tls-cert-file value                 [$TLS_CERT_FILE]
22--tls-private-key value               [$TLS_PRIVATE_KEY]
23--temp-path value                    path to temp files (default: "/tmp") [$TEMP_PATH]
24--web-path value                     path to static web files [$WEB_PATH]
25--proxy-path value                   path prefix when service is run behind a proxy [$PROXY_PATH]
26--proxy-port value                   port of the proxy when the service is run behind a proxy [$PROXY_PORT]
27--email-contact value                email address to link in Contact Us (front end) [$EMAIL_CONTACT]
28--ga-key value                       key for google analytics (front end) [$GA_KEY]
29--uservoice-key value                key for user voice (front end) [$USERVOICE_KEY]
30--provider value                     s3|gdrive|local [$PROVIDER]
31--s3-endpoint value                   [$S3_ENDPOINT]
32--s3-region value                    (default: "eu-west-1") [$S3_REGION]
33--aws-access-key value                [$AWS_ACCESS_KEY]
34--aws-secret-key value                [$AWS_SECRET_KEY]
35--bucket value                        [$BUCKET]
36--s3-no-multipart                    Disables S3 Multipart Puts [$S3_NO_MULTIPART]
37--s3-path-style                      Forces path style URLs, required for Minio. [$S3_PATH_STYLE]
38--gdrive-client-json-filepath value   [$GDRIVE_CLIENT_JSON_FILEPATH]
39--gdrive-local-config-path value      [$GDRIVE_LOCAL_CONFIG_PATH]
40--gdrive-chunk-size value            (default: 16) [$GDRIVE_CHUNK_SIZE]
41--storj-access value                 Access for the project [$STORJ_ACCESS]
42--storj-bucket value                 Bucket to use within the project [$STORJ_BUCKET]
43--rate-limit value                   requests per minute (default: 0) [$RATE_LIMIT]
44--purge-days value                   number of days after uploads are purged automatically (default: 0) [$PURGE_DAYS]
45--purge-interval value               interval in hours to run the automatic purge for (default: 0) [$PURGE_INTERVAL]
46--max-upload-size value              max limit for upload, in kilobytes (default: 0) [$MAX_UPLOAD_SIZE]
47--lets-encrypt-hosts value           host1, host2 [$HOSTS]
48--log value                          /var/log/transfersh.log [$LOG]
49--basedir value                      path to storage [$BASEDIR]
50--clamav-host value                  clamav-host [$CLAMAV_HOST]
51--perform-clamav-prescan             perform-clamav-prescan [$PERFORM_CLAMAV_PRESCAN]
52--virustotal-key value               virustotal-key [$VIRUSTOTAL_KEY]
53--profiler                           enable profiling [$PROFILER]
54--http-auth-user value               user for http basic auth [$HTTP_AUTH_USER]
55--http-auth-pass value               pass for http basic auth [$HTTP_AUTH_PASS]
56--ip-whitelist value                 comma separated list of ips allowed to connect to the service [$IP_WHITELIST]
57--ip-blacklist value                 comma separated list of ips not allowed to connect to the service [$IP_BLACKLIST]
58--cors-domains value                 comma separated list of domains allowed for CORS requests [$CORS_DOMAINS]
59--random-token-length value          (default: 6) [$RANDOM_TOKEN_LENGTH]
60--help, -h                           show help
61apiVersion: apps/v1
62kind: Deployment
63metadata:
64  name: transfer-sh
65  namespace: transfer-sh
66  labels:
67    app: "transfer-sh"
68spec:
69  replicas: 1
70  selector:
71    matchLabels:
72      app: transfer-sh
73  template:
74    metadata:
75      labels:
76        app: transfer-sh
77    spec:
78      containers:
79      - name: transfer-sh
80        image: dutchcoders/transfer.sh:latest
81        args:
82        - "--provider local"
83        - "--basedir /tmp"
84        ports:
85        - containerPort: 8080
86

I intentionally have not included any persistent volume claims yet. At this point I'm just testing to make sure the container will run.

Initially, I though maybe it was some sort of escape sequence issue. After trying all manner of ways to potentially escape the two dashes nothing really changed. I also tried setting environment variables that contained those arguments, but that just resulted in the same behavior where --profile turned into -profile.

If anyone has any thoughts I could use the help. I'm a bit stuck at the moment (although still troubleshooting). I am curious if maybe there is a different way to pass in command flags as opposed to arguments (or maybe there isn't any difference as far as k8s is concerned).

ANSWER

Answered 2022-Mar-12 at 02:46

Try:

1docker run -d -p 8080:8080 --name transfer-sh -v /tmp:/tmp dutchcoders/transfer.sh:latest --provider local --basedir /tmp
2NAME:
3transfer.sh - transfer.sh
4
5DESCRIPTION:
6Easy file sharing from the command line
7
8USAGE:
9transfer.sh [flags] command [arguments...]
10
11COMMANDS:
12version
13help, h  Shows a list of commands or help for one command
14
15FLAGS:
16--listener value                     127.0.0.1:8080 (default: "127.0.0.1:8080") [$LISTENER]
17--profile-listener value             127.0.0.1:6060 [$PROFILE_LISTENER]
18--force-https                         [$FORCE_HTTPS]
19--tls-listener value                 127.0.0.1:8443 [$TLS_LISTENER]
20--tls-listener-only                   [$TLS_LISTENER_ONLY]
21--tls-cert-file value                 [$TLS_CERT_FILE]
22--tls-private-key value               [$TLS_PRIVATE_KEY]
23--temp-path value                    path to temp files (default: "/tmp") [$TEMP_PATH]
24--web-path value                     path to static web files [$WEB_PATH]
25--proxy-path value                   path prefix when service is run behind a proxy [$PROXY_PATH]
26--proxy-port value                   port of the proxy when the service is run behind a proxy [$PROXY_PORT]
27--email-contact value                email address to link in Contact Us (front end) [$EMAIL_CONTACT]
28--ga-key value                       key for google analytics (front end) [$GA_KEY]
29--uservoice-key value                key for user voice (front end) [$USERVOICE_KEY]
30--provider value                     s3|gdrive|local [$PROVIDER]
31--s3-endpoint value                   [$S3_ENDPOINT]
32--s3-region value                    (default: "eu-west-1") [$S3_REGION]
33--aws-access-key value                [$AWS_ACCESS_KEY]
34--aws-secret-key value                [$AWS_SECRET_KEY]
35--bucket value                        [$BUCKET]
36--s3-no-multipart                    Disables S3 Multipart Puts [$S3_NO_MULTIPART]
37--s3-path-style                      Forces path style URLs, required for Minio. [$S3_PATH_STYLE]
38--gdrive-client-json-filepath value   [$GDRIVE_CLIENT_JSON_FILEPATH]
39--gdrive-local-config-path value      [$GDRIVE_LOCAL_CONFIG_PATH]
40--gdrive-chunk-size value            (default: 16) [$GDRIVE_CHUNK_SIZE]
41--storj-access value                 Access for the project [$STORJ_ACCESS]
42--storj-bucket value                 Bucket to use within the project [$STORJ_BUCKET]
43--rate-limit value                   requests per minute (default: 0) [$RATE_LIMIT]
44--purge-days value                   number of days after uploads are purged automatically (default: 0) [$PURGE_DAYS]
45--purge-interval value               interval in hours to run the automatic purge for (default: 0) [$PURGE_INTERVAL]
46--max-upload-size value              max limit for upload, in kilobytes (default: 0) [$MAX_UPLOAD_SIZE]
47--lets-encrypt-hosts value           host1, host2 [$HOSTS]
48--log value                          /var/log/transfersh.log [$LOG]
49--basedir value                      path to storage [$BASEDIR]
50--clamav-host value                  clamav-host [$CLAMAV_HOST]
51--perform-clamav-prescan             perform-clamav-prescan [$PERFORM_CLAMAV_PRESCAN]
52--virustotal-key value               virustotal-key [$VIRUSTOTAL_KEY]
53--profiler                           enable profiling [$PROFILER]
54--http-auth-user value               user for http basic auth [$HTTP_AUTH_USER]
55--http-auth-pass value               pass for http basic auth [$HTTP_AUTH_PASS]
56--ip-whitelist value                 comma separated list of ips allowed to connect to the service [$IP_WHITELIST]
57--ip-blacklist value                 comma separated list of ips not allowed to connect to the service [$IP_BLACKLIST]
58--cors-domains value                 comma separated list of domains allowed for CORS requests [$CORS_DOMAINS]
59--random-token-length value          (default: 6) [$RANDOM_TOKEN_LENGTH]
60--help, -h                           show help
61apiVersion: apps/v1
62kind: Deployment
63metadata:
64  name: transfer-sh
65  namespace: transfer-sh
66  labels:
67    app: "transfer-sh"
68spec:
69  replicas: 1
70  selector:
71    matchLabels:
72      app: transfer-sh
73  template:
74    metadata:
75      labels:
76        app: transfer-sh
77    spec:
78      containers:
79      - name: transfer-sh
80        image: dutchcoders/transfer.sh:latest
81        args:
82        - "--provider local"
83        - "--basedir /tmp"
84        ports:
85        - containerPort: 8080
86apiVersion: apps/v1
87kind: Deployment
88metadata:
89  name: transfer-sh
90  namespace: transfer-sh
91  labels:
92    app: transfer-sh
93spec:
94  replicas: 1
95  selector:
96    matchLabels:
97      app: transfer-sh
98  template:
99    metadata:
100      labels:
101        app: transfer-sh
102    spec:
103      containers:
104      - name: transfer-sh
105        image: dutchcoders/transfer.sh:latest
106        args:  # <-- in this case each arg is individual
107        - --provider
108        - local
109        - --basedir
110        - /tmp
111        ports:
112        - containerPort: 8080
113
114
115NAME          READY   UP-TO-DATE   AVAILABLE   AGE
116transfer-sh   1/1     1            1           91s
117

Source https://stackoverflow.com/questions/71446454

QUESTION

How to build a Loki server Docker image using Docker-compose

Asked 2022-Feb-23 at 08:16

I have created a directory and mounted all the required files in each directory but when I try to create the docker image, It creates Promtail and Grafana but the LOKI wouldn't create. I get the error message below;

ERROR: for 9c35c983e8e4_cbxs_loki_1 Cannot start service loki: Mounts denied: You can configure shared paths from Docker -> Preferences... -> Resources -> File Sharing.

I have mounted the files just as the order containers.. Please help

docker-compose.yml

Please see the file on the link below https://docs.technotim.live/posts/grafana-loki/

1version: "3"
2networks:
3  loki:
4services:
5  loki:
6    image: grafana/loki:2.4.0
7    ports:
8      - "3100:3100"
9    restart: unless-stopped
10    command: -config.file=/etc/loki/loki-config.yml
11    networks:
12      - loki
13  promtail:
14    image: grafana/promtail:2.4.0
15    volumes:
16      - /var/log:/var/log
17      - /Users/emma.egbu/CBCS/Promtail:/etc/promtail
18    ports:
19      - "1514:1514"
20    restart: unless-stopped
21    command: -config.file=/etc/promtail/promtail-config.yml
22    networks:
23      - loki
24  grafana:
25    image: grafana/grafana:latest
26    user: "1000"
27    volumes:
28    - /Users/emma.egbu/CBCS/Grafana:/var/lib/grafana
29    ports:
30      - "3000:3000"
31    restart: unless-stopped
32    networks:
33      - loki
34

Thank you so much ! That was helpful... For anyone going through the same struggle, here was what I did: I went to edit the docker daemon config file sudo nano /etc/docker/daemon.json - Probably you won't have write access so sudo vi chmod 666 /etc/docker/daemon.json - This will allow u write I pasted the file below

1version: "3"
2networks:
3  loki:
4services:
5  loki:
6    image: grafana/loki:2.4.0
7    ports:
8      - "3100:3100"
9    restart: unless-stopped
10    command: -config.file=/etc/loki/loki-config.yml
11    networks:
12      - loki
13  promtail:
14    image: grafana/promtail:2.4.0
15    volumes:
16      - /var/log:/var/log
17      - /Users/emma.egbu/CBCS/Promtail:/etc/promtail
18    ports:
19      - "1514:1514"
20    restart: unless-stopped
21    command: -config.file=/etc/promtail/promtail-config.yml
22    networks:
23      - loki
24  grafana:
25    image: grafana/grafana:latest
26    user: "1000"
27    volumes:
28    - /Users/emma.egbu/CBCS/Grafana:/var/lib/grafana
29    ports:
30      - "3000:3000"
31    restart: unless-stopped
32    networks:
33      - loki
34{
35    "log-driver": "loki",
36    "log-opts": {
37        "loki-url": "http://localhost:3100/loki/api/v1/push",
38        "loki-batch-size": "400"
39    }
40

Afterwards I restarted my docker then also docker-compose up -d --force-recreate - to run up the docker-compose file

ANSWER

Answered 2022-Feb-09 at 10:55

You have defined a volume mount for /var/log in your container, but most likely don't have this defined in Docker Desktop (under Docker -> Preferences... -> Resources -> File Sharing). You are probably best off removing this volume definition from the compose file, unless you actually want to read these logs on your Mac.

Source https://stackoverflow.com/questions/71045993

QUESTION

Inter-process communication (C++ to C#) using Memory mapped file (IOException)

Asked 2022-Feb-23 at 06:57

There are two processes: one written in C++ and the other written in C#.

Simply, C++ process will create a file name "test.dat", map the file to its memory, and keep on writing on it.

C# process on the other hand will open the file and read whenever there is a change on the memory.

The problem is that on the C# end, it does not let me open the file. (IOException saying the other process is in use"

Here is what I've tested.

1//C++
2// Test create & open
3void CTestDlg::OnBnClickedBtn1()
4{
5    WCHAR wcsDebug[1024];
6    HANDLE hFile, hMapFile;
7
8    UINT size = sizeof(syncData);
9
10    hFile = CreateFile(L"C:\\Users\\test\\Documents\\2134\\test.dat", GENERIC_READ | GENERIC_WRITE,
11        FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
12
13    if (hFile != INVALID_HANDLE_VALUE)
14    {
15        hMapFile = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, size, NULL);
16
17        if (hMapFile)
18        {
19            g_pb = (BYTE*)MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
20        }
21    }
22}
23
24// Test Writing 
25void CLibTestDlg::OnBnClickedBtn2()
26{
27    WCHAR sz[] = L"C:\\Users\\test\\Documents\\2134\\";
28    WCHAR wcsFilePath[MAX_PATH];
29
30    CString str;
31    GetDlgItemText(IDC_EDIT_FID, str);
32
33
34    if (str != L"\0")
35    {
36        swprintf_s(wcsFilePath, _countof(wcsFilePath), L"%s%s", sz, str.GetBuffer());
37
38        if (g_pb)
39        {
40            syncData sd;
41
42            sd.dwCurrent = nCurr;
43            sd.dwTotal = 15;
44            sd.eSyncType = TYPE_DOWNLOAD;
45
46            StringCchCopy(sd.wcsFileName, _countof(sd.wcsFileName), wcsFilePath);
47            sd.eReqType = TYPE_DOWNLOAD;
48            sd.ullTimeStamp = GetTickCount();
49
50            nCurr++;
51
52            memcpy(g_pb, &sd, sizeof(sd));
53        }
54    }
55}
56
57

C# portion below:

1//C++
2// Test create & open
3void CTestDlg::OnBnClickedBtn1()
4{
5    WCHAR wcsDebug[1024];
6    HANDLE hFile, hMapFile;
7
8    UINT size = sizeof(syncData);
9
10    hFile = CreateFile(L"C:\\Users\\test\\Documents\\2134\\test.dat", GENERIC_READ | GENERIC_WRITE,
11        FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
12
13    if (hFile != INVALID_HANDLE_VALUE)
14    {
15        hMapFile = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, size, NULL);
16
17        if (hMapFile)
18        {
19            g_pb = (BYTE*)MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
20        }
21    }
22}
23
24// Test Writing 
25void CLibTestDlg::OnBnClickedBtn2()
26{
27    WCHAR sz[] = L"C:\\Users\\test\\Documents\\2134\\";
28    WCHAR wcsFilePath[MAX_PATH];
29
30    CString str;
31    GetDlgItemText(IDC_EDIT_FID, str);
32
33
34    if (str != L"\0")
35    {
36        swprintf_s(wcsFilePath, _countof(wcsFilePath), L"%s%s", sz, str.GetBuffer());
37
38        if (g_pb)
39        {
40            syncData sd;
41
42            sd.dwCurrent = nCurr;
43            sd.dwTotal = 15;
44            sd.eSyncType = TYPE_DOWNLOAD;
45
46            StringCchCopy(sd.wcsFileName, _countof(sd.wcsFileName), wcsFilePath);
47            sd.eReqType = TYPE_DOWNLOAD;
48            sd.ullTimeStamp = GetTickCount();
49
50            nCurr++;
51
52            memcpy(g_pb, &sd, sizeof(sd));
53        }
54    }
55}
56
57        private void Button_MouseUp(object sender, RoutedEventArgs e)
58        {
59            Console.WriteLine("Click");
60
61            FileStream fs = File.Open(@"C:\\Users\\test\\Documents\\2134\\test.dat", FileMode.Open, FileAccess.ReadWrite); // Error Here! IOException: The file is being used by another process.
62
63            using (var mmf = MemoryMappedFile.CreateFromFile(fs, "mmf", 0, MemoryMappedFileAccess.ReadWrite, HandleInheritability.None, true))
64            {
65                using (var accessor = mmf.CreateViewAccessor(0, 544))
66                {
67                    DWORD dwCurrent;
68                    accessor.Read(0, out dwCurrent);
69
70                    Console.WriteLine("Hello" + dwCurrent);
71                }
72            }
73        }
74

Any ideas on approaching the file sharing between the two processes?

ANSWER

Answered 2022-Feb-23 at 06:57

FileStream defaults to only allowing read sharing which is not compatible with how you've opened your c++ file. You need to request write sharing too:

1//C++
2// Test create & open
3void CTestDlg::OnBnClickedBtn1()
4{
5    WCHAR wcsDebug[1024];
6    HANDLE hFile, hMapFile;
7
8    UINT size = sizeof(syncData);
9
10    hFile = CreateFile(L"C:\\Users\\test\\Documents\\2134\\test.dat", GENERIC_READ | GENERIC_WRITE,
11        FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
12
13    if (hFile != INVALID_HANDLE_VALUE)
14    {
15        hMapFile = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, size, NULL);
16
17        if (hMapFile)
18        {
19            g_pb = (BYTE*)MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
20        }
21    }
22}
23
24// Test Writing 
25void CLibTestDlg::OnBnClickedBtn2()
26{
27    WCHAR sz[] = L"C:\\Users\\test\\Documents\\2134\\";
28    WCHAR wcsFilePath[MAX_PATH];
29
30    CString str;
31    GetDlgItemText(IDC_EDIT_FID, str);
32
33
34    if (str != L"\0")
35    {
36        swprintf_s(wcsFilePath, _countof(wcsFilePath), L"%s%s", sz, str.GetBuffer());
37
38        if (g_pb)
39        {
40            syncData sd;
41
42            sd.dwCurrent = nCurr;
43            sd.dwTotal = 15;
44            sd.eSyncType = TYPE_DOWNLOAD;
45
46            StringCchCopy(sd.wcsFileName, _countof(sd.wcsFileName), wcsFilePath);
47            sd.eReqType = TYPE_DOWNLOAD;
48            sd.ullTimeStamp = GetTickCount();
49
50            nCurr++;
51
52            memcpy(g_pb, &sd, sizeof(sd));
53        }
54    }
55}
56
57        private void Button_MouseUp(object sender, RoutedEventArgs e)
58        {
59            Console.WriteLine("Click");
60
61            FileStream fs = File.Open(@"C:\\Users\\test\\Documents\\2134\\test.dat", FileMode.Open, FileAccess.ReadWrite); // Error Here! IOException: The file is being used by another process.
62
63            using (var mmf = MemoryMappedFile.CreateFromFile(fs, "mmf", 0, MemoryMappedFileAccess.ReadWrite, HandleInheritability.None, true))
64            {
65                using (var accessor = mmf.CreateViewAccessor(0, 544))
66                {
67                    DWORD dwCurrent;
68                    accessor.Read(0, out dwCurrent);
69
70                    Console.WriteLine("Hello" + dwCurrent);
71                }
72            }
73        }
74File.Open(@"...", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
75

Source https://stackoverflow.com/questions/71232149

QUESTION

Is it possible to open a PDF file from a database-fetched Uri from Android API 28?

Asked 2022-Feb-17 at 17:36

I am writing a file sharing app for Android (>= API 28) and I have the following use case:

  1. A user uploads a file from their local storage.
  2. The user closes the app and after a while reopens it, causing the app to request the list of files to the server to populate the layout.
  3. The user clicks on a file to preview it.

At this point, the most intuitive step would be, given that the app knows the file URL, just load it inside a WebView pointing to i.e. Google Docs' https://docs.google.com/viewerng/viewer?url=$myFileUrl or any other file viewing service.

Truth is, I don't want my app to excessively cling on to an external service, so I thought at the moment of the file upload (step 1), a content:// Uri is attached and stored in a database to use it in step 3.

That way, if the user hasn't renamed and moved the file he uploaded, the app could attempt to open the file locally, saving some bandwidth usage.

As @CommonsWare wrote in this article, the time the app has permission to access a Uri is limited; in my case it only lasts until the user closes the app. That means using a strategy such as:

MainActivity.kt

1// Getting the content:// Uri after a call to the server.
2viewModel.selectedUrl.observe(this@MainActivity) { uri ->
3   val newIntent = Intent(Intent.ACTION_VIEW)
4   try {
5      newIntent.data = Uri.parse(uri)
6      newIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
7      newIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
8      try {
9         startActivity(newIntent)
10      } catch (e: ActivityNotFoundException) {
11         Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show()
12      }
13   // ...
14}
15

Will only work if the file is uploaded and opened straight away. Is it possible to solve this issue in any way or should I just stick to the WebView option which does not involve any Uri?

UPDATE: How is the file uploaded?

In my MainActivity I have a FAB which, when clicked, triggers the following snippet:

MainActivity.kt

1// Getting the content:// Uri after a call to the server.
2viewModel.selectedUrl.observe(this@MainActivity) { uri ->
3   val newIntent = Intent(Intent.ACTION_VIEW)
4   try {
5      newIntent.data = Uri.parse(uri)
6      newIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
7      newIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
8      try {
9         startActivity(newIntent)
10      } catch (e: ActivityNotFoundException) {
11         Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show()
12      }
13   // ...
14}
15val fileResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
16        viewModel.uploadFile(result, false) // This is the Uri.
17    }
18
19fileFab.setOnClickListener {
20    val intent = Intent()
21    intent.type = "application/*"
22    intent.action = Intent.ACTION_OPEN_DOCUMENT
23    fileResultLauncher.launch(intent)
24}
25

...which after the respective ViewModel.kt and Repository.kt calls it ends up in a Server class with the method:

Server.kt

1// Getting the content:// Uri after a call to the server.
2viewModel.selectedUrl.observe(this@MainActivity) { uri ->
3   val newIntent = Intent(Intent.ACTION_VIEW)
4   try {
5      newIntent.data = Uri.parse(uri)
6      newIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
7      newIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
8      try {
9         startActivity(newIntent)
10      } catch (e: ActivityNotFoundException) {
11         Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show()
12      }
13   // ...
14}
15val fileResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
16        viewModel.uploadFile(result, false) // This is the Uri.
17    }
18
19fileFab.setOnClickListener {
20    val intent = Intent()
21    intent.type = "application/*"
22    intent.action = Intent.ACTION_OPEN_DOCUMENT
23    fileResultLauncher.launch(intent)
24}
25override fun uploadFile(uri: Uri, title: String, isSound: Boolean, callback: IFileUploadCallback) {
26    Timber.d("Uploading document...")
27    val inputStream = c.contentResolver.openInputStream(uri)
28    var fileData: ByteArray? = null
29    inputStream?.buffered()?.use {
30        fileData = it.readBytes()
31    }
32    fileData?: return
33
34    // Call to Volley
35    // ...
36

ANSWER

Answered 2022-Feb-17 at 17:36

Thanks to @blackapps and @CommonsWare, I was missing the following line in my ViewModel class:

1// Getting the content:// Uri after a call to the server.
2viewModel.selectedUrl.observe(this@MainActivity) { uri ->
3   val newIntent = Intent(Intent.ACTION_VIEW)
4   try {
5      newIntent.data = Uri.parse(uri)
6      newIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
7      newIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
8      try {
9         startActivity(newIntent)
10      } catch (e: ActivityNotFoundException) {
11         Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show()
12      }
13   // ...
14}
15val fileResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
16        viewModel.uploadFile(result, false) // This is the Uri.
17    }
18
19fileFab.setOnClickListener {
20    val intent = Intent()
21    intent.type = "application/*"
22    intent.action = Intent.ACTION_OPEN_DOCUMENT
23    fileResultLauncher.launch(intent)
24}
25override fun uploadFile(uri: Uri, title: String, isSound: Boolean, callback: IFileUploadCallback) {
26    Timber.d("Uploading document...")
27    val inputStream = c.contentResolver.openInputStream(uri)
28    var fileData: ByteArray? = null
29    inputStream?.buffered()?.use {
30        fileData = it.readBytes()
31    }
32    fileData?: return
33
34    // Call to Volley
35    // ...
36context.contentResolver.takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
37

ViewModel.kt

1// Getting the content:// Uri after a call to the server.
2viewModel.selectedUrl.observe(this@MainActivity) { uri ->
3   val newIntent = Intent(Intent.ACTION_VIEW)
4   try {
5      newIntent.data = Uri.parse(uri)
6      newIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
7      newIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
8      try {
9         startActivity(newIntent)
10      } catch (e: ActivityNotFoundException) {
11         Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show()
12      }
13   // ...
14}
15val fileResultLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
16        viewModel.uploadFile(result, false) // This is the Uri.
17    }
18
19fileFab.setOnClickListener {
20    val intent = Intent()
21    intent.type = "application/*"
22    intent.action = Intent.ACTION_OPEN_DOCUMENT
23    fileResultLauncher.launch(intent)
24}
25override fun uploadFile(uri: Uri, title: String, isSound: Boolean, callback: IFileUploadCallback) {
26    Timber.d("Uploading document...")
27    val inputStream = c.contentResolver.openInputStream(uri)
28    var fileData: ByteArray? = null
29    inputStream?.buffered()?.use {
30        fileData = it.readBytes()
31    }
32    fileData?: return
33
34    // Call to Volley
35    // ...
36context.contentResolver.takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
37fun uploadFile(result: ActivityResult) {
38    if (result.resultCode == Activity.RESULT_OK) {
39        val uri: Uri = result.data?.data!!
40        context.contentResolver.takePersistableUriPermission(uri, Intent.FLAG_GRANT_READ_URI_PERMISSION)
41        viewModelScope.launch(Dispatchers.IO) {
42            repository.uploadFile(uri, object: Server.IFileUploadCallback {
43                override fun onSuccess(fileUrl: String, content: String) {
44                    uploadedFileUrl.postValue(RecyclerViewItem.Document(fileUrl, content, uri))
45                }
46            })
47        }
48    }
49}
50

Source https://stackoverflow.com/questions/71157018

QUESTION

Docker failed to start on Windows 11

Asked 2022-Feb-12 at 17:01

I intend to run a Linux-based container on Windows. I installed Docker 4.3.2 and 4.4.4 community editions based on WLS2 to do that. After enabling all prerequisites for windows (WSL2, Hyper-V, Containers) and installing Docker, I tried to launch the docker desktop, at first, the docker icon appears on the taskbar but after a few seconds it disappears without showing any error message.

System specification:

  • OS: Windows 11 pro version 21H2 Build 22000.376
  • Docker version: 4.3.2 community edition
  • WSL: wsl v2

enter image description here

Here is the log for last try:

1[001:21:20:01.354][I] (25d488c5) 2784eefb-BackendAPI S<-C 5cad5efc-GoBackendClient-CSharp GET /settings
2[   at Docker.Core.HttpClientExtensions.<GetJsonAsync>d__0`1.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\HttpClientExtensions.cs:line 16
3[   at Docker.Core.HttpClientExtensions.GetJsonAsync[T](HttpClient httpClient, String uri, CancellationToken cancellationToken)
4[   at Docker.Core.GoBackend.GoBackendClient.GetSettingsAsync() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\GoBackend\GoBackendClient.cs:line 248
5[   at Docker.Core.SettingsLoader.<WatchSettingsFile>d__9.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\SettingsLoader.cs:line 71
6[   at Docker.Core.SettingsLoader.WatchSettingsFile()
7[001:21:20:01.356][I] (25d488c5) 2784eefb-BackendAPI S->C 5cad5efc-GoBackendClient-CSharp GET /settings (542.5µs): {"acceptCanaryUpdates":false,"activeOrganizationName":"","analyticsEnabled":true,"autoDownloadUpdates":false,"autoStart":true,"cpus":2,"credentialHelper":"docker-credential-wincred.exe","customWslDistroDir":"","dataFolder":"C:\\ProgramData\\DockerDesktop\\vm-data","disableHardwareAcceleration":false,"disableTips":false,"disableUpdate":false,"diskSizeMiB":65536,"diskTRIM":true,"displayRestartDialog":true,"displaySwitchVersionPack":true,"displaySwitchWinLinContainers":true,"displayed18362Deprecation":false,"displayedElectronPopup":[],"displayedTutorial":false,"dns":"8.8.8.8","enableIntegrationWithDefaultWslDistro":true,"exposeDockerAPIOnTCP2375":false,"filesharingDirectories":[],"integratedWslDistros":[],"kubernetesEnabled":false,"kubernetesInitialInstallPerformed":false,"lastLoginDate":0,"latestBannerKey":"","licenseTermsVersion":2,"lifecycleTimeoutSeconds":600,"memoryMiB":2048,"openUIOnStartupDisabled":false,"overrideProxyExclude":"","overrideProxyHttp":"","overrideProxyHttps":"","proxyHttpMode":"system","settingsVersion":16,"showKubernetesSystemContainers":false,"skipUpdateToWSLPrompt":true,"skipWSLMountPerfWarning":false,"socksProxyPort":0,"swapMiB":1024,"swarmFederationExplicitlyLoggedOut":false,"synchronizedDirectories":[],"tipLastId":"float64","tipLastViewedTime":0,"updateAvailableTime":0,"updatePopupAppearanceTime":0,"updateSkippedBuild":"","useCredentialHelper":true,"useDnsForwarder":true,"useNightlyBuildUpdates":false,"useVirtualizationFramework":false,"useVpnkit":true,"useWindowsContainers":false,"versionPack":"default","vpnKitMaxPortIdleTime":"float64","vpnKitTransparentProxy":false,"vpnkitCIDR":"1...4","wslEnableGrpcfuse":false,"wslEngineEnabled":true}
8[001:21:20:01.357][I] (18c069ce) 2784eefb-BackendAPI S<-C 5cad5efc-GoBackendClient-CSharp GET /ping
9[   at Docker.Core.GoBackend.GoBackendClient.WaitForServer(Object state) in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\GoBackend\GoBackendClient.cs:line 88
10[001:21:20:01.357][I] (18c069ce) 2784eefb-BackendAPI S->C 5cad5efc-GoBackendClient-CSharp GET /ping (0s): {"serverTime":1641043201357640200}
11[001:21:20:01.482][I] (3a878ee0) 2784eefb-BackendAPI S<-C 5cad5efc-GoBackendClient-CSharp GET /settings
12[   at Docker.Core.HttpClientExtensions.<GetJsonAsync>d__0`1.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\HttpClientExtensions.cs:line 16
13[   at Docker.Core.HttpClientExtensions.GetJsonAsync[T](HttpClient httpClient, String uri, CancellationToken cancellationToken)
14[   at Docker.Core.GoBackend.GoBackendClient.GetSettingsAsync() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\GoBackend\GoBackendClient.cs:line 248
15[   at Docker.Core.SettingsLoader.<<OnChanged>b__10_0>d.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\SettingsLoader.cs:line 102
16[   at Docker.Core.SettingsLoader.<OnChanged>b__10_0()
17[001:21:20:01.483][I] (3a878ee0) 2784eefb-BackendAPI S->C 5cad5efc-GoBackendClient-CSharp GET /settings (1.1523ms): {"acceptCanaryUpdates":false,"activeOrganizationName":"","analyticsEnabled":true,"autoDownloadUpdates":false,"autoStart":true,"cpus":2,"credentialHelper":"docker-credential-wincred.exe","customWslDistroDir":"","dataFolder":"C:\\ProgramData\\DockerDesktop\\vm-data","disableHardwareAcceleration":false,"disableTips":false,"disableUpdate":false,"diskSizeMiB":65536,"diskTRIM":true,"displayRestartDialog":true,"displaySwitchVersionPack":true,"displaySwitchWinLinContainers":true,"displayed18362Deprecation":false,"displayedElectronPopup":[],"displayedTutorial":false,"dns":"8.8.8.8","enableIntegrationWithDefaultWslDistro":true,"exposeDockerAPIOnTCP2375":false,"filesharingDirectories":[],"integratedWslDistros":[],"kubernetesEnabled":false,"kubernetesInitialInstallPerformed":false,"lastLoginDate":0,"latestBannerKey":"","licenseTermsVersion":2,"lifecycleTimeoutSeconds":600,"memoryMiB":2048,"openUIOnStartupDisabled":false,"overrideProxyExclude":"","overrideProxyHttp":"","overrideProxyHttps":"","proxyHttpMode":"system","settingsVersion":16,"showKubernetesSystemContainers":false,"skipUpdateToWSLPrompt":true,"skipWSLMountPerfWarning":false,"socksProxyPort":0,"swapMiB":1024,"swarmFederationExplicitlyLoggedOut":false,"synchronizedDirectories":[],"tipLastId":"float64","tipLastViewedTime":0,"updateAvailableTime":0,"updatePopupAppearanceTime":0,"updateSkippedBuild":"","useCredentialHelper":true,"useDnsForwarder":true,"useNightlyBuildUpdates":false,"useVirtualizationFramework":false,"useVpnkit":true,"useWindowsContainers":false,"versionPack":"default","vpnKitMaxPortIdleTime":"float64","vpnKitTransparentProxy":false,"vpnkitCIDR":"1...4","wslEnableGrpcfuse":false,"wslEngineEnabled":true}
18[001:21:20:01.506][I] (b724d811) 2784eefb-BackendAPI S<-C 5cad5efc-GoBackendClient-CSharp GET /settings
19[   at Docker.Core.HttpClientExtensions.<GetJsonAsync>d__0`1.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\HttpClientExtensions.cs:line 16
20[   at Docker.Core.HttpClientExtensions.GetJsonAsync[T](HttpClient httpClient, String uri, CancellationToken cancellationToken)
21[   at Docker.Core.GoBackend.GoBackendClient.GetSettingsAsync() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\GoBackend\GoBackendClient.cs:line 248
22[   at Docker.Core.SettingsLoader.<<OnChanged>b__10_0>d.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\SettingsLoader.cs:line 102
23[   at Docker.Core.SettingsLoader.<OnChanged>b__10_0()
24[001:21:20:01.506][I] (b724d811) 2784eefb-BackendAPI S->C 5cad5efc-GoBackendClient-CSharp GET /settings (557.5µs): {"acceptCanaryUpdates":false,"activeOrganizationName":"","analyticsEnabled":true,"autoDownloadUpdates":false,"autoStart":true,"cpus":2,"credentialHelper":"docker-credential-wincred.exe","customWslDistroDir":"","dataFolder":"C:\\ProgramData\\DockerDesktop\\vm-data","disableHardwareAcceleration":false,"disableTips":false,"disableUpdate":false,"diskSizeMiB":65536,"diskTRIM":true,"displayRestartDialog":true,"displaySwitchVersionPack":true,"displaySwitchWinLinContainers":true,"displayed18362Deprecation":false,"displayedElectronPopup":[],"displayedTutorial":false,"dns":"8.8.8.8","enableIntegrationWithDefaultWslDistro":true,"exposeDockerAPIOnTCP2375":false,"filesharingDirectories":[],"integratedWslDistros":[],"kubernetesEnabled":false,"kubernetesInitialInstallPerformed":false,"lastLoginDate":0,"latestBannerKey":"","licenseTermsVersion":2,"lifecycleTimeoutSeconds":600,"memoryMiB":2048,"openUIOnStartupDisabled":false,"overrideProxyExclude":"","overrideProxyHttp":"","overrideProxyHttps":"","proxyHttpMode":"system","settingsVersion":16,"showKubernetesSystemContainers":false,"skipUpdateToWSLPrompt":true,"skipWSLMountPerfWarning":false,"socksProxyPort":0,"swapMiB":1024,"swarmFederationExplicitlyLoggedOut":false,"synchronizedDirectories":[],"tipLastId":"float64","tipLastViewedTime":0,"updateAvailableTime":0,"updatePopupAppearanceTime":0,"updateSkippedBuild":"","useCredentialHelper":true,"useDnsForwarder":true,"useNightlyBuildUpdates":false,"useVirtualizationFramework":false,"useVpnkit":true,"useWindowsContainers":false,"versionPack":"default","vpnKitMaxPortIdleTime":"float64","vpnKitTransparentProxy":false,"vpnkitCIDR":"1...4","wslEnableGrpcfuse":false,"wslEngineEnabled":true}
25[001:21:20:01.544][I] (dafb5e19) 2784eefb-BackendAPI S<-C 5cad5efc-GoBackendClient-CSharp GET /features
26[   at Docker.Core.GoBackend.GoBackendClient.<GetFeaturesAsync>d__15.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\GoBackend\GoBackendClient.cs:line 196
27[   at Docker.Core.GoBackend.GoBackendClient.GetFeaturesAsync()
28[   at Docker.Core.Features.Features.get_FeatureList() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\Features\Features.cs:line 21
29[   at Docker.Core.Features.Features.GetEnabled() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\Features\Features.cs:line 74
30[   at Docker.ApiServices.Analytics.SegmentApi.<Track>d__21.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.ApiServices\Analytics\Analytics.cs:line 115
31[   at Docker.ApiServices.Analytics.SegmentApi.Track(String eventType, IDictionary`2 additionalProperties, Settings settings)
32[   at Docker.ApiServices.Analytics.SegmentApi.<TrackAsync>d__19.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.ApiServices\Analytics\Analytics.cs:line 70
33[   at Docker.ApiServices.Analytics.SegmentApi.TrackAsync(AnalyticEvents analyticEvent, IDictionary`2 additionalProperties)
34[   at Docker.Program.Run(IReadOnlyCollection`1 args) in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Desktop\Program.cs:line 235
35[   at Docker.Program.Main(String[] args) in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Desktop\Program.cs:line 131
36[001:21:20:01.550][I] (dafb5e19) 2784eefb-BackendAPI S->C 5cad5efc-GoBackendClient-CSharp GET /features (1.1525ms): {"Auth0":{"description":"Login and authentication is handled by auth0","enabled":false,"label":"Perform login via auth0","name":"Login via auth0","type":1},"NightlyBuilds":{"description":"Switch the application update to the night builds","enabled":false,"label":"Enable nightly builds","name":"Nightly builds","type":1},"ProUser":{"description":"You can upgrade your current tier [here](URL)","enabled":false,"label":"personal","name":"ProUser","type":3},"Procd":{"description":"Enable advanced process management functionality like suspend and resume of containers and the VM","enabled":true,"label":"Enable process management daemon","name":"Process management daemon","type":1},"SignInBanner":{"description":"Show persistent non-dismissible banner to encourage sign in","enabled":false,"label":"Display sign in banner if not logged in","name":"Sign in banner","type":1},"SimultaneousLinuxAndWindowsContainers":{"description":"Allow both Linux and Windows containers simultaneously using docker cli contexts","enabled":false,"label":"Simultaneous Linux and Windows containers","name":"Simultaneous Linux and Windows containers","type":3},"WhaleMenuRedesign":{"description":"Display Whale menu done with Electron","enabled":false,"label":"Enable Whale Menu Redesign","name":"Whale Menu Redesign","type":1},"grpcfuseV2":{"description":"Switch off to use the legacy osxfs file sharing instead.","enabled":true,"label":"Use grpcfuse for filesharing by default","name":"Grpcfuse","type":1},"mutagenV0":{"description":"Use Mutagen to synchronize files in a container with your local disk.","enabled":false,"label":"Two-way file synchronisation","name":"Mutagen","type":1}}
37

Failed tries:

1[001:21:20:01.354][I] (25d488c5) 2784eefb-BackendAPI S<-C 5cad5efc-GoBackendClient-CSharp GET /settings
2[   at Docker.Core.HttpClientExtensions.<GetJsonAsync>d__0`1.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\HttpClientExtensions.cs:line 16
3[   at Docker.Core.HttpClientExtensions.GetJsonAsync[T](HttpClient httpClient, String uri, CancellationToken cancellationToken)
4[   at Docker.Core.GoBackend.GoBackendClient.GetSettingsAsync() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\GoBackend\GoBackendClient.cs:line 248
5[   at Docker.Core.SettingsLoader.<WatchSettingsFile>d__9.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\SettingsLoader.cs:line 71
6[   at Docker.Core.SettingsLoader.WatchSettingsFile()
7[001:21:20:01.356][I] (25d488c5) 2784eefb-BackendAPI S->C 5cad5efc-GoBackendClient-CSharp GET /settings (542.5µs): {"acceptCanaryUpdates":false,"activeOrganizationName":"","analyticsEnabled":true,"autoDownloadUpdates":false,"autoStart":true,"cpus":2,"credentialHelper":"docker-credential-wincred.exe","customWslDistroDir":"","dataFolder":"C:\\ProgramData\\DockerDesktop\\vm-data","disableHardwareAcceleration":false,"disableTips":false,"disableUpdate":false,"diskSizeMiB":65536,"diskTRIM":true,"displayRestartDialog":true,"displaySwitchVersionPack":true,"displaySwitchWinLinContainers":true,"displayed18362Deprecation":false,"displayedElectronPopup":[],"displayedTutorial":false,"dns":"8.8.8.8","enableIntegrationWithDefaultWslDistro":true,"exposeDockerAPIOnTCP2375":false,"filesharingDirectories":[],"integratedWslDistros":[],"kubernetesEnabled":false,"kubernetesInitialInstallPerformed":false,"lastLoginDate":0,"latestBannerKey":"","licenseTermsVersion":2,"lifecycleTimeoutSeconds":600,"memoryMiB":2048,"openUIOnStartupDisabled":false,"overrideProxyExclude":"","overrideProxyHttp":"","overrideProxyHttps":"","proxyHttpMode":"system","settingsVersion":16,"showKubernetesSystemContainers":false,"skipUpdateToWSLPrompt":true,"skipWSLMountPerfWarning":false,"socksProxyPort":0,"swapMiB":1024,"swarmFederationExplicitlyLoggedOut":false,"synchronizedDirectories":[],"tipLastId":"float64","tipLastViewedTime":0,"updateAvailableTime":0,"updatePopupAppearanceTime":0,"updateSkippedBuild":"","useCredentialHelper":true,"useDnsForwarder":true,"useNightlyBuildUpdates":false,"useVirtualizationFramework":false,"useVpnkit":true,"useWindowsContainers":false,"versionPack":"default","vpnKitMaxPortIdleTime":"float64","vpnKitTransparentProxy":false,"vpnkitCIDR":"1...4","wslEnableGrpcfuse":false,"wslEngineEnabled":true}
8[001:21:20:01.357][I] (18c069ce) 2784eefb-BackendAPI S<-C 5cad5efc-GoBackendClient-CSharp GET /ping
9[   at Docker.Core.GoBackend.GoBackendClient.WaitForServer(Object state) in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\GoBackend\GoBackendClient.cs:line 88
10[001:21:20:01.357][I] (18c069ce) 2784eefb-BackendAPI S->C 5cad5efc-GoBackendClient-CSharp GET /ping (0s): {"serverTime":1641043201357640200}
11[001:21:20:01.482][I] (3a878ee0) 2784eefb-BackendAPI S<-C 5cad5efc-GoBackendClient-CSharp GET /settings
12[   at Docker.Core.HttpClientExtensions.<GetJsonAsync>d__0`1.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\HttpClientExtensions.cs:line 16
13[   at Docker.Core.HttpClientExtensions.GetJsonAsync[T](HttpClient httpClient, String uri, CancellationToken cancellationToken)
14[   at Docker.Core.GoBackend.GoBackendClient.GetSettingsAsync() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\GoBackend\GoBackendClient.cs:line 248
15[   at Docker.Core.SettingsLoader.<<OnChanged>b__10_0>d.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\SettingsLoader.cs:line 102
16[   at Docker.Core.SettingsLoader.<OnChanged>b__10_0()
17[001:21:20:01.483][I] (3a878ee0) 2784eefb-BackendAPI S->C 5cad5efc-GoBackendClient-CSharp GET /settings (1.1523ms): {"acceptCanaryUpdates":false,"activeOrganizationName":"","analyticsEnabled":true,"autoDownloadUpdates":false,"autoStart":true,"cpus":2,"credentialHelper":"docker-credential-wincred.exe","customWslDistroDir":"","dataFolder":"C:\\ProgramData\\DockerDesktop\\vm-data","disableHardwareAcceleration":false,"disableTips":false,"disableUpdate":false,"diskSizeMiB":65536,"diskTRIM":true,"displayRestartDialog":true,"displaySwitchVersionPack":true,"displaySwitchWinLinContainers":true,"displayed18362Deprecation":false,"displayedElectronPopup":[],"displayedTutorial":false,"dns":"8.8.8.8","enableIntegrationWithDefaultWslDistro":true,"exposeDockerAPIOnTCP2375":false,"filesharingDirectories":[],"integratedWslDistros":[],"kubernetesEnabled":false,"kubernetesInitialInstallPerformed":false,"lastLoginDate":0,"latestBannerKey":"","licenseTermsVersion":2,"lifecycleTimeoutSeconds":600,"memoryMiB":2048,"openUIOnStartupDisabled":false,"overrideProxyExclude":"","overrideProxyHttp":"","overrideProxyHttps":"","proxyHttpMode":"system","settingsVersion":16,"showKubernetesSystemContainers":false,"skipUpdateToWSLPrompt":true,"skipWSLMountPerfWarning":false,"socksProxyPort":0,"swapMiB":1024,"swarmFederationExplicitlyLoggedOut":false,"synchronizedDirectories":[],"tipLastId":"float64","tipLastViewedTime":0,"updateAvailableTime":0,"updatePopupAppearanceTime":0,"updateSkippedBuild":"","useCredentialHelper":true,"useDnsForwarder":true,"useNightlyBuildUpdates":false,"useVirtualizationFramework":false,"useVpnkit":true,"useWindowsContainers":false,"versionPack":"default","vpnKitMaxPortIdleTime":"float64","vpnKitTransparentProxy":false,"vpnkitCIDR":"1...4","wslEnableGrpcfuse":false,"wslEngineEnabled":true}
18[001:21:20:01.506][I] (b724d811) 2784eefb-BackendAPI S<-C 5cad5efc-GoBackendClient-CSharp GET /settings
19[   at Docker.Core.HttpClientExtensions.<GetJsonAsync>d__0`1.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\HttpClientExtensions.cs:line 16
20[   at Docker.Core.HttpClientExtensions.GetJsonAsync[T](HttpClient httpClient, String uri, CancellationToken cancellationToken)
21[   at Docker.Core.GoBackend.GoBackendClient.GetSettingsAsync() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\GoBackend\GoBackendClient.cs:line 248
22[   at Docker.Core.SettingsLoader.<<OnChanged>b__10_0>d.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\SettingsLoader.cs:line 102
23[   at Docker.Core.SettingsLoader.<OnChanged>b__10_0()
24[001:21:20:01.506][I] (b724d811) 2784eefb-BackendAPI S->C 5cad5efc-GoBackendClient-CSharp GET /settings (557.5µs): {"acceptCanaryUpdates":false,"activeOrganizationName":"","analyticsEnabled":true,"autoDownloadUpdates":false,"autoStart":true,"cpus":2,"credentialHelper":"docker-credential-wincred.exe","customWslDistroDir":"","dataFolder":"C:\\ProgramData\\DockerDesktop\\vm-data","disableHardwareAcceleration":false,"disableTips":false,"disableUpdate":false,"diskSizeMiB":65536,"diskTRIM":true,"displayRestartDialog":true,"displaySwitchVersionPack":true,"displaySwitchWinLinContainers":true,"displayed18362Deprecation":false,"displayedElectronPopup":[],"displayedTutorial":false,"dns":"8.8.8.8","enableIntegrationWithDefaultWslDistro":true,"exposeDockerAPIOnTCP2375":false,"filesharingDirectories":[],"integratedWslDistros":[],"kubernetesEnabled":false,"kubernetesInitialInstallPerformed":false,"lastLoginDate":0,"latestBannerKey":"","licenseTermsVersion":2,"lifecycleTimeoutSeconds":600,"memoryMiB":2048,"openUIOnStartupDisabled":false,"overrideProxyExclude":"","overrideProxyHttp":"","overrideProxyHttps":"","proxyHttpMode":"system","settingsVersion":16,"showKubernetesSystemContainers":false,"skipUpdateToWSLPrompt":true,"skipWSLMountPerfWarning":false,"socksProxyPort":0,"swapMiB":1024,"swarmFederationExplicitlyLoggedOut":false,"synchronizedDirectories":[],"tipLastId":"float64","tipLastViewedTime":0,"updateAvailableTime":0,"updatePopupAppearanceTime":0,"updateSkippedBuild":"","useCredentialHelper":true,"useDnsForwarder":true,"useNightlyBuildUpdates":false,"useVirtualizationFramework":false,"useVpnkit":true,"useWindowsContainers":false,"versionPack":"default","vpnKitMaxPortIdleTime":"float64","vpnKitTransparentProxy":false,"vpnkitCIDR":"1...4","wslEnableGrpcfuse":false,"wslEngineEnabled":true}
25[001:21:20:01.544][I] (dafb5e19) 2784eefb-BackendAPI S<-C 5cad5efc-GoBackendClient-CSharp GET /features
26[   at Docker.Core.GoBackend.GoBackendClient.<GetFeaturesAsync>d__15.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\GoBackend\GoBackendClient.cs:line 196
27[   at Docker.Core.GoBackend.GoBackendClient.GetFeaturesAsync()
28[   at Docker.Core.Features.Features.get_FeatureList() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\Features\Features.cs:line 21
29[   at Docker.Core.Features.Features.GetEnabled() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Core\Features\Features.cs:line 74
30[   at Docker.ApiServices.Analytics.SegmentApi.<Track>d__21.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.ApiServices\Analytics\Analytics.cs:line 115
31[   at Docker.ApiServices.Analytics.SegmentApi.Track(String eventType, IDictionary`2 additionalProperties, Settings settings)
32[   at Docker.ApiServices.Analytics.SegmentApi.<TrackAsync>d__19.MoveNext() in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.ApiServices\Analytics\Analytics.cs:line 70
33[   at Docker.ApiServices.Analytics.SegmentApi.TrackAsync(AnalyticEvents analyticEvent, IDictionary`2 additionalProperties)
34[   at Docker.Program.Run(IReadOnlyCollection`1 args) in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Desktop\Program.cs:line 235
35[   at Docker.Program.Main(String[] args) in C:\workspaces\4.3.x\src\github.com\docker\pinata\win\src\Docker.Desktop\Program.cs:line 131
36[001:21:20:01.550][I] (dafb5e19) 2784eefb-BackendAPI S->C 5cad5efc-GoBackendClient-CSharp GET /features (1.1525ms): {"Auth0":{"description":"Login and authentication is handled by auth0","enabled":false,"label":"Perform login via auth0","name":"Login via auth0","type":1},"NightlyBuilds":{"description":"Switch the application update to the night builds","enabled":false,"label":"Enable nightly builds","name":"Nightly builds","type":1},"ProUser":{"description":"You can upgrade your current tier [here](URL)","enabled":false,"label":"personal","name":"ProUser","type":3},"Procd":{"description":"Enable advanced process management functionality like suspend and resume of containers and the VM","enabled":true,"label":"Enable process management daemon","name":"Process management daemon","type":1},"SignInBanner":{"description":"Show persistent non-dismissible banner to encourage sign in","enabled":false,"label":"Display sign in banner if not logged in","name":"Sign in banner","type":1},"SimultaneousLinuxAndWindowsContainers":{"description":"Allow both Linux and Windows containers simultaneously using docker cli contexts","enabled":false,"label":"Simultaneous Linux and Windows containers","name":"Simultaneous Linux and Windows containers","type":3},"WhaleMenuRedesign":{"description":"Display Whale menu done with Electron","enabled":false,"label":"Enable Whale Menu Redesign","name":"Whale Menu Redesign","type":1},"grpcfuseV2":{"description":"Switch off to use the legacy osxfs file sharing instead.","enabled":true,"label":"Use grpcfuse for filesharing by default","name":"Grpcfuse","type":1},"mutagenV0":{"description":"Use Mutagen to synchronize files in a container with your local disk.","enabled":false,"label":"Two-way file synchronisation","name":"Mutagen","type":1}}
371- check with different version of Docker desktop 2,3,4.3.2,4.4.4
382- Reconfig the JSON file
393- disable and enabling Docker related services on windows (Hyper-v, Containers, WSL2)
404- updating WSL2 
415- installing different Linux distributions on WSL2
426- running the Docker services manually
437- running DockerCli on privileged permission using PowerShell
448- running Docker debugger tools to identify the problem
459- search on Docker repository for a similar issue
46

ANSWER

Answered 2022-Jan-01 at 15:48

Did you try to restart, read the doc on how to get it installed. Make sure that you have hyper-v enabled as well as windows WSL system features.

Source https://stackoverflow.com/questions/70549119

QUESTION

Should I use GridFS or some other method to create a file sharing app?

Asked 2022-Feb-11 at 17:56

I am currently beginning work on a file sharing app for my company. A simple form to upload a file, the user is then given a download URL and can past that on to anyone so they can download the file (Similar to products such as WeTransfer).

However I am struggling on decided how to do it. I have been playing with MongoDB and GridFS. I have successfully used multer and multer-gridfs-storage to upload files directly into my database. I am struggling to get them to download as I don't know that much about GridFS.

1const storage = new GridFsStorage({
2url: 'mongodb://localhost:27017/fileUpload',
3file: (req, file) => {
4    return new Promise((resolve, reject) => {
5        crypto.randomBytes(16, (err, buf) => {
6            if (err) {
7                return reject(err)
8            }
9            const filename = buf.toString('hex') + path.extname(file.originalname);
10            const fileInfo = {
11                filename: filename,
12                bucketName: 'uploads'
13            };
14            resolve(fileInfo)
15        });
16    });
17}
18}); 
19
20const upload = multer({ storage })
21

But it got me thinking is this the best way of doing this or would there be a better why or serving those download files (to download to a users computer).

Any advice is greatly appreciated!

ANSWER

Answered 2022-Feb-11 at 17:56

GridFS is a specification for storing and retrieving files that exceed the BSON document size limit of 16 MB. GridFS is a convention implemented by all MongoDB drivers that stores binary data across many smaller documents. The binaries are split into the chunks and then the chunks are stored in collections created by GridFS.

Having said that, given the presented use cases i would highly recommend using media server for storage as given the application landscape, that makes a more economical, viable and scalable solution.

Having said that, I would generally, avoid putting BLOBs in the database if there are other storage options that cost less as using a database as BLOB store is generally not a cost optimised solution. Sure, there are valid reasons for storing blobs in the database, but given the application’s use case (it being media intensive), use the media server for file storage, and databases for data structures.

In such cases, It is often easy to get "cost unoptimized" with time. Plus the database size would grow exponentially with time, bringing it's own challenges with RAM (WiredTiger Cache) management.

All in all - if it was me - I would use media storage for BLOB intensive applications than relying on databases.

Source https://stackoverflow.com/questions/71082705

QUESTION

TCP transfer files without closing socket

Asked 2022-Feb-04 at 20:35

I coded a simple TCP server - client file sharing but it only work when the script close the socket in the client side.

I tried to remove the s.close inside the client python script and it gave me an error. Any idea? I dont know if it even possible to do this kind of things with TCP without closing socket.

here is my code

server.py

1import socket
2import tqdm
3import os
4
5SERVER_HOST = "192.168.1.48"
6SERVER_PORT = 5001
7
8BUFFER_SIZE = 4096
9SEPARATOR = "<SEPARATOR>"
10
11s = socket.socket()
12s.bind((SERVER_HOST, SERVER_PORT))
13
14s.listen(5)
15print(f"[*] Listening as {SERVER_HOST}:{SERVER_PORT}")
16
17client_socket, address = s.accept()
18
19print(f"[+] {address} is connected.")
20
21
22def receive_file(filename):
23
24    received = client_socket.recv(BUFFER_SIZE).decode()
25    filename, filesize = received.split(SEPARATOR)
26 
27    filename = os.path.basename(filename)
28  
29    filesize = int(filesize)
30
31    progress = tqdm.tqdm(range(filesize), f"Receiving {filename}", unit="B", unit_scale=True, unit_divisor=1024)
32    with open(filename, "wb") as f:
33        while True:
34            # read 1024 bytes from the socket (receive)
35            bytes_read = client_socket.recv(BUFFER_SIZE)
36            if not bytes_read:
37                # nothing is received
38                # file transmitting is done
39                break
40            # write to the file the bytes we just received
41            f.write(bytes_read)
42            # update the progress bar
43            progress.update(len(bytes_read))
44
45while True:
46    command = input("-->")
47    client_socket.send(str.encode(command))
48    filename = command[9:]
49    receive_file(filename)
50    
51
52

client.py

1import socket
2import tqdm
3import os
4
5SERVER_HOST = "192.168.1.48"
6SERVER_PORT = 5001
7
8BUFFER_SIZE = 4096
9SEPARATOR = "<SEPARATOR>"
10
11s = socket.socket()
12s.bind((SERVER_HOST, SERVER_PORT))
13
14s.listen(5)
15print(f"[*] Listening as {SERVER_HOST}:{SERVER_PORT}")
16
17client_socket, address = s.accept()
18
19print(f"[+] {address} is connected.")
20
21
22def receive_file(filename):
23
24    received = client_socket.recv(BUFFER_SIZE).decode()
25    filename, filesize = received.split(SEPARATOR)
26 
27    filename = os.path.basename(filename)
28  
29    filesize = int(filesize)
30
31    progress = tqdm.tqdm(range(filesize), f"Receiving {filename}", unit="B", unit_scale=True, unit_divisor=1024)
32    with open(filename, "wb") as f:
33        while True:
34            # read 1024 bytes from the socket (receive)
35            bytes_read = client_socket.recv(BUFFER_SIZE)
36            if not bytes_read:
37                # nothing is received
38                # file transmitting is done
39                break
40            # write to the file the bytes we just received
41            f.write(bytes_read)
42            # update the progress bar
43            progress.update(len(bytes_read))
44
45while True:
46    command = input("-->")
47    client_socket.send(str.encode(command))
48    filename = command[9:]
49    receive_file(filename)
50    
51
52import socket
53import tqdm
54import os
55
56SEPARATOR = "<SEPARATOR>"
57BUFFER_SIZE = 4096 # send 4096 bytes each time step
58
59
60
61host = "192.168.1.48"
62
63port = 5001
64
65filesize = os.path.getsize(filename)
66s = socket.socket()
67
68print(f"[+] Connecting to {host}:{port}")
69s.connect((host, port))
70print("[+] Connected.")
71
72def send_file(filename,filesize):
73
74    s.send(f"{filename}{SEPARATOR}{filesize}".encode())
75
76   
77    progress = tqdm.tqdm(range(filesize), f"Sending {filename}", unit="B", unit_scale=True, unit_divisor=1024)
78    with open(filename, "rb") as f:
79        while True:
80            
81            bytes_read = f.read(BUFFER_SIZE)
82            if not bytes_read:
83                # file transmitting is done
84                break
85          
86            s.sendall(bytes_read)
87       
88            progress.update(len(bytes_read))
89    # close the socket
90    s.close()
91
92
93while True:
94    command = s.recv(4096)
95    if command[:8].decode("utf-8") == "download":
96        print("yes it start")
97        filename = command[9:].decode("utf-8")
98        print(filename)
99        filesize = os.path.getsize(filename)
100        send_file(filename,filesize)
101
102

ANSWER

Answered 2022-Feb-04 at 20:35

Break out of the loop when you've received filesize bytes.

1import socket
2import tqdm
3import os
4
5SERVER_HOST = "192.168.1.48"
6SERVER_PORT = 5001
7
8BUFFER_SIZE = 4096
9SEPARATOR = "<SEPARATOR>"
10
11s = socket.socket()
12s.bind((SERVER_HOST, SERVER_PORT))
13
14s.listen(5)
15print(f"[*] Listening as {SERVER_HOST}:{SERVER_PORT}")
16
17client_socket, address = s.accept()
18
19print(f"[+] {address} is connected.")
20
21
22def receive_file(filename):
23
24    received = client_socket.recv(BUFFER_SIZE).decode()
25    filename, filesize = received.split(SEPARATOR)
26 
27    filename = os.path.basename(filename)
28  
29    filesize = int(filesize)
30
31    progress = tqdm.tqdm(range(filesize), f"Receiving {filename}", unit="B", unit_scale=True, unit_divisor=1024)
32    with open(filename, "wb") as f:
33        while True:
34            # read 1024 bytes from the socket (receive)
35            bytes_read = client_socket.recv(BUFFER_SIZE)
36            if not bytes_read:
37                # nothing is received
38                # file transmitting is done
39                break
40            # write to the file the bytes we just received
41            f.write(bytes_read)
42            # update the progress bar
43            progress.update(len(bytes_read))
44
45while True:
46    command = input("-->")
47    client_socket.send(str.encode(command))
48    filename = command[9:]
49    receive_file(filename)
50    
51
52import socket
53import tqdm
54import os
55
56SEPARATOR = "<SEPARATOR>"
57BUFFER_SIZE = 4096 # send 4096 bytes each time step
58
59
60
61host = "192.168.1.48"
62
63port = 5001
64
65filesize = os.path.getsize(filename)
66s = socket.socket()
67
68print(f"[+] Connecting to {host}:{port}")
69s.connect((host, port))
70print("[+] Connected.")
71
72def send_file(filename,filesize):
73
74    s.send(f"{filename}{SEPARATOR}{filesize}".encode())
75
76   
77    progress = tqdm.tqdm(range(filesize), f"Sending {filename}", unit="B", unit_scale=True, unit_divisor=1024)
78    with open(filename, "rb") as f:
79        while True:
80            
81            bytes_read = f.read(BUFFER_SIZE)
82            if not bytes_read:
83                # file transmitting is done
84                break
85          
86            s.sendall(bytes_read)
87       
88            progress.update(len(bytes_read))
89    # close the socket
90    s.close()
91
92
93while True:
94    command = s.recv(4096)
95    if command[:8].decode("utf-8") == "download":
96        print("yes it start")
97        filename = command[9:].decode("utf-8")
98        print(filename)
99        filesize = os.path.getsize(filename)
100        send_file(filename,filesize)
101
102    with open(filename, "wb") as f:
103        total_bytes = 0
104        while total_bytes < filesize:
105            # read 1024 bytes from the socket (receive)
106            bytes_read = client_socket.recv(BUFFER_SIZE)
107            if not bytes_read:
108                # nothing is received
109                # file transmitting is done
110                break
111            # write to the file the bytes we just received
112            f.write(bytes_read)
113            total_bytes += len(bytes_read)
114            # update the progress bar
115            progress.update(len(bytes_read))
116

Source https://stackoverflow.com/questions/70992517

QUESTION

WebRTC onicecandidate not getting called in cordova android, but is getting called in browser

Asked 2022-Jan-02 at 21:25

I am working on a file sharing project which works on WebRTC, Cordova and Framework7. My code works perfectly fine in a browser but whenever I try to run the same code through an android emulator with Cordova the WebRTC onicecandidate function never seems to get called and I don't get any error messages. If possible I don't want to use any third party libraries and just reuse the same javascript code I already wrote.

1function createPeerConn() {
2let conf = {
3    iceServers: [{ urls: "stun:stun.l.google.com:19302" }],
4};
5myConn = new RTCPeerConnection(conf, { optional: [] });
6myConn.onicecandidate = function (event) {
7    if (event.candidate) {
8        socket.emit("candidate", event.candidate);
9        console.log("create peer con called.")
10    }
11};
12openDataChannel();
13} 
14

ANSWER

Answered 2021-Dec-31 at 13:49

That would be because RTCIceServers.urls is not supported by ANDROID Webview as per https://developer.mozilla.org/en-US/docs/Web/API/RTCIceServer/urls

Source https://stackoverflow.com/questions/70534080

QUESTION

How to disable static file serving with hunchentoot?

Asked 2021-Dec-15 at 16:50

I was browsing hunchentoot documentation and source files for the better part of last night but could not find a hint as to how to disable static file serving.

All I want is to write a few handlers, which reply to HTTP Post requests. Since I did not find any hints as to how to disable static file sharing in the documentation, I feel unable to give any "coding attempt" here, along with this question.

My current (untested first attempt) is, giving :document-root the value nil but it is undocumented what hunchentoot will do with that (either what I want or use default root-dir...).

1(let ((acceptor (make-instance 'hunchentoot:easy-acceptor
2                 :port port
3                 :document-root nil
4                 :name 'storage-acceptor)))
5   ;; ...
6)
7

The fact, that hunchentoot seems to use CLOS heavily makes it even harder for me, because I usually avoid CLOS and stick to "normal" lisp programming (also for performance reasons...).

The other point of confusion of hunchentoot arises from some (for me, at least) new kind of global variable usage (I never saw defvar-unbound or anything similar before).

So, if you provide sample snippets of how to disable file serving with hunchentoot, do not assume too much about my CLOS and global variable technique knowledge.

Also, I want to use the single-threaded-acceptor in my code, because hunchentoot will run in an lparallel task on a single thread in my program. Not sure if that has an impact on your answers, though.

ANSWER

Answered 2021-Dec-15 at 16:50

From reading the initialization and use in acceptor.lisp, I'd be pretty sure that setting document-root explicitly to nil will disable lookup of static files from the file system. I agree that this should be tested and added to the documentation.

Source https://stackoverflow.com/questions/70355053

QUESTION

The torrent program was stopped by the DoS attack. I want to know the reason

Asked 2021-Dec-01 at 11:06

When a qBittorrent torrent client (A) shares a file (Seeding == A), the attacker implemented UDP flooding on the IP and PORT used by Qbittorrent. As a result, file sharing was not possible, and other users who were downloading the file were also disconnected from Seeder(A). However, the Internet speed in the network was normal, and the Internet speed of the attacked user (A) was also slightly slow in the normal range. The users who downloaded the file were in the wireless LAN environment, and the attacker and Seeder (A) were in the wired LAN environment. What do you think is the reason? No matter how much I think about it, I do not understand that only the torrent client is slow and the internet speed is normal.

ANSWER

Answered 2021-Nov-29 at 12:27

Given the vague description it's impossible to know for sure. But perhaps what the question is aiming at is that not all denial of service attacks target the network.

DoS attacks overwhelm a target system until something breaks. Sometimes it's the network, but it can also be other things. Maybe in this case, the machine running the client was overwhelmed before the network did by running out of a resource like CPU or memory.

Source https://stackoverflow.com/questions/70152580

Community Discussions contain sources that include Stack Exchange Network

Tutorials and Learning Resources in File Sharing

Tutorials and Learning Resources are not available at this moment for File Sharing

Share this Page

share link

Get latest updates on File Sharing