-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Azure-specific headers when uploading to blob storage #1784
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -790,20 +790,24 @@ def upload_file( | |
filename=to_upload.name, | ||
) | ||
|
||
extra_headers = self.get_extra_headers_for_protocol(upload_location.native_url) | ||
encoded_md5 = b64encode(md5_bytes) | ||
with open(str(to_upload), "+rb") as local_file: | ||
content = local_file.read() | ||
content_length = len(content) | ||
headers = {"Content-Length": str(content_length), "Content-MD5": encoded_md5} | ||
headers.update(extra_headers) | ||
rsp = requests.put( | ||
upload_location.signed_url, | ||
data=content, | ||
headers={"Content-Length": str(content_length), "Content-MD5": encoded_md5}, | ||
headers=headers, | ||
verify=False | ||
if self._config.platform.insecure_skip_verify is True | ||
else self._config.platform.ca_cert_file_path, | ||
) | ||
|
||
if rsp.status_code != requests.codes["OK"]: | ||
# Check both HTTP 201 and 200, because some storage backends (e.g. Azure) return 201 instead of 200. | ||
if rsp.status_code not in (requests.codes["OK"], requests.codes["created"]): | ||
raise FlyteValueException( | ||
rsp.status_code, | ||
f"Request to send data {upload_location.signed_url} failed.", | ||
|
@@ -1925,3 +1929,9 @@ def launch_backfill( | |
return remote_wf | ||
|
||
return self.execute(remote_wf, inputs={}, project=project, domain=domain, execution_name=execution_name) | ||
|
||
@staticmethod | ||
def get_extra_headers_for_protocol(native_url): | ||
if native_url.startswith("abfs://"): | ||
return {"x-ms-blob-type": "BlockBlob"} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the case of blockblob type, the return code will become 200, won't it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like it returns a 201 https://learn.microsoft.com/en-us/rest/api/storageservices/put-blob?tabs=azure-ad#status-code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That matches what happened when I tested it |
||
return {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we have to check this value as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, forgot to specify in my PR description.
Azure returns an HTTP 201. So this was throwing an exception even though the request was successful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add this as a comment please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done