kandi background
kandi background
Explore Kits
kandi background
Explore Kits
kandi background
Explore Kits
kandi background
Explore Kits
Explore all Cloud Storage open source software, libraries, packages, source code, cloud functions and APIs.

Popular New Releases in Cloud Storage

Bugfix release

rclone v1.58.0

3.0.0

3.1.4

Release version 1.91

minio

Bugfix release

rclone

rclone v1.58.0

flysystem

3.0.0

formidable

3.1.4

s3fs-fuse

Release version 1.91

Popular Libraries in Cloud Storage

Trending New libraries in Cloud Storage

Top Authors in Cloud Storage

1

23 Libraries

967

2

18 Libraries

2268

3

12 Libraries

3655

4

11 Libraries

37645

5

8 Libraries

102

6

7 Libraries

1005

7

6 Libraries

362

8

5 Libraries

111

9

5 Libraries

38

10

5 Libraries

549

1

23 Libraries

967

2

18 Libraries

2268

3

12 Libraries

3655

4

11 Libraries

37645

5

8 Libraries

102

6

7 Libraries

1005

7

6 Libraries

362

8

5 Libraries

111

9

5 Libraries

38

10

5 Libraries

549

Trending Kits in Cloud Storage

No Trending Kits are available at this moment for Cloud Storage

Trending Discussions on Cloud Storage

    Upload a modified XML file to google cloud storage after editting it with ElementTree (python)
    Google Cloud Function succeeds, but not showing expected output
    Does Hub support integrations for MinIO, AWS, and GCP? If so, how does it work?
    Compress & Upload large videos to Google cloud storage using Flutter/Dart
    How to grant access to google cloud storage buckets based on users auth uid
    How to delete a Cloud Storage file after it has been downloaded?
    How to ensure access the right backend M3U8 file in origin cluster mode
    Terraform Firebase Web Application
    Access specific folder in GCS bucket according to user, using Workload Identity Federation
    Debugging a Google Dataflow Streaming Job that does not work expected

QUESTION

Upload a modified XML file to google cloud storage after editting it with ElementTree (python)

Asked 2022-Mar-25 at 17:35

I've modified a piece of code for merging two or more xml files into one. I got it working locally without using or storing files on google cloud storage.

I'd like to use it via cloud functions, which seems to work mostly fine, apart from uploading the final xml file to google cloud storage.

1import os
2import wget
3import logging
4
5from io import BytesIO
6from google.cloud import storage
7from xml.etree import ElementTree as ET
8
9def merge(event, context):
10    client = storage.Client()
11    bucket = client.get_bucket('mybucket')
12    test1 = bucket.blob("xml-file1.xml")
13    inputxml1 = test1.download_as_string()
14    root1 = ET.fromstring(inputxml1)
15    test2 = bucket.blob("xml-file2.xml")
16    inputxml2 = test2.download_as_string()
17    root2 = ET.fromstring(inputxml2)
18    copy_files = [e for e in root1.findall('./SHOPITEM')]
19    src_files = set([e.find('./SHOPITEM') for e in copy_files])
20    copy_files.extend([e for e in root2.findall('./SHOPITEM') if e.find('./CODE').text not in src_files])
21    files = ET.Element('SHOP')
22    files.extend(copy_files)
23    blob = bucket.blob("test.xml")
24    blob.upload_from_string(files)
25

Ive tried the functions .write and .tostring but unsuccessfully.

ANSWER

Answered 2022-Mar-25 at 17:35

Sorry for the incomplete question. I've already found a solution and I cant recall the error message I got. Here is my solution:

copy icondownload icon

1import os
2import wget
3import logging
4
5from io import BytesIO
6from google.cloud import storage
7from xml.etree import ElementTree as ET
8
9def merge(event, context):
10    client = storage.Client()
11    bucket = client.get_bucket('mybucket')
12    test1 = bucket.blob("xml-file1.xml")
13    inputxml1 = test1.download_as_string()
14    root1 = ET.fromstring(inputxml1)
15    test2 = bucket.blob("xml-file2.xml")
16    inputxml2 = test2.download_as_string()
17    root2 = ET.fromstring(inputxml2)
18    copy_files = [e for e in root1.findall('./SHOPITEM')]
19    src_files = set([e.find('./SHOPITEM') for e in copy_files])
20    copy_files.extend([e for e in root2.findall('./SHOPITEM') if e.find('./CODE').text not in src_files])
21    files = ET.Element('SHOP')
22    files.extend(copy_files)
23    blob = bucket.blob("test.xml")
24    blob.upload_from_string(files)
25blob.upload_from_string(ET.tostring(files, encoding='UTF-8',xml_declaration=True, method='xml').decode('UTF-8'),content_type='application/xml')
26

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

Community Discussions contain sources that include Stack Exchange Network

    Upload a modified XML file to google cloud storage after editting it with ElementTree (python)
    Google Cloud Function succeeds, but not showing expected output
    Does Hub support integrations for MinIO, AWS, and GCP? If so, how does it work?
    Compress & Upload large videos to Google cloud storage using Flutter/Dart
    How to grant access to google cloud storage buckets based on users auth uid
    How to delete a Cloud Storage file after it has been downloaded?
    How to ensure access the right backend M3U8 file in origin cluster mode
    Terraform Firebase Web Application
    Access specific folder in GCS bucket according to user, using Workload Identity Federation
    Debugging a Google Dataflow Streaming Job that does not work expected

QUESTION

Upload a modified XML file to google cloud storage after editting it with ElementTree (python)

Asked 2022-Mar-25 at 17:35

I've modified a piece of code for merging two or more xml files into one. I got it working locally without using or storing files on google cloud storage.

I'd like to use it via cloud functions, which seems to work mostly fine, apart from uploading the final xml file to google cloud storage.

1import os
2import wget
3import logging
4
5from io import BytesIO
6from google.cloud import storage
7from xml.etree import ElementTree as ET
8
9def merge(event, context):
10    client = storage.Client()
11    bucket = client.get_bucket('mybucket')
12    test1 = bucket.blob("xml-file1.xml")
13    inputxml1 = test1.download_as_string()
14    root1 = ET.fromstring(inputxml1)
15    test2 = bucket.blob("xml-file2.xml")
16    inputxml2 = test2.download_as_string()
17    root2 = ET.fromstring(inputxml2)
18    copy_files = [e for e in root1.findall('./SHOPITEM')]
19    src_files = set([e.find('./SHOPITEM') for e in copy_files])
20    copy_files.extend([e for e in root2.findall('./SHOPITEM') if e.find('./CODE').text not in src_files])
21    files = ET.Element('SHOP')
22    files.extend(copy_files)
23    blob = bucket.blob("test.xml")
24    blob.upload_from_string(files)
25

Ive tried the functions .write and .tostring but unsuccessfully.

ANSWER

Answered 2022-Mar-25 at 17:35

Sorry for the incomplete question. I've already found a solution and I cant recall the error message I got. Here is my solution:

copy icondownload icon

1import os
2import wget
3import logging
4
5from io import BytesIO
6from google.cloud import storage
7from xml.etree import ElementTree as ET
8
9def merge(event, context):
10    client = storage.Client()
11    bucket = client.get_bucket('mybucket')
12    test1 = bucket.blob("xml-file1.xml")
13    inputxml1 = test1.download_as_string()
14    root1 = ET.fromstring(inputxml1)
15    test2 = bucket.blob("xml-file2.xml")
16    inputxml2 = test2.download_as_string()
17    root2 = ET.fromstring(inputxml2)
18    copy_files = [e for e in root1.findall('./SHOPITEM')]
19    src_files = set([e.find('./SHOPITEM') for e in copy_files])
20    copy_files.extend([e for e in root2.findall('./SHOPITEM') if e.find('./CODE').text not in src_files])
21    files = ET.Element('SHOP')
22    files.extend(copy_files)
23    blob = bucket.blob("test.xml")
24    blob.upload_from_string(files)
25blob.upload_from_string(ET.tostring(files, encoding='UTF-8',xml_declaration=True, method='xml').decode('UTF-8'),content_type='application/xml')
26

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