-
Notifications
You must be signed in to change notification settings - Fork 2
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
Fixes Issue 123 #132
Fixes Issue 123 #132
Conversation
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.
I noticed a few things in your approach that don't align with our goals. The goal is to upload directly to GCS without saving locally, but there are some additions like local file saving, bucket creation in each mission, and local logging that add unnecessary complexity. Please take a moment to review the guide, it seems that some complexity has been added.
|
||
@app.route('/uploadMission', methods=['POST']) | ||
def upload_file(): | ||
log_text = "" | ||
airsim_app = AirSimApplication() # Create an instance of AirSimApplication | ||
|
||
try: | ||
file = request.files['file'] | ||
filename = file.filename | ||
if not filename: | ||
raise ValueError("No file Provided"); | ||
|
||
custom_mission_dir = '../multirotor/mission/custom' | ||
path = os.path.join(custom_mission_dir, filename) | ||
file.save(path) | ||
|
||
#Code for Log success | ||
|
||
airsim_app.append_pass_to_log(f"Report '{filename}' successfully uploaded at {path}.") | ||
log_text = airsim_app.log_text # Get the updated log text | ||
logger.info(log_text) # Log to file | ||
print(log_text) # Print to console for visibility | ||
|
||
# Return success response to the frontend | ||
return jsonify({'message': log_text, 'status': 'success'}), 200 | ||
|
||
except Exception as e: | ||
# Handle errors and log failure message | ||
airsim_app.append_fail_to_log(f"Failed to upload report: {str(e)}") | ||
log_text = airsim_app.log_text # Get the updated log text | ||
logger.error(log_text) # Log error | ||
print(log_text) # Print error to console | ||
|
||
# Return failure response to the frontend | ||
return jsonify({'message': log_text, 'status': 'failure'}), 500 | ||
|
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.
upload_file in airsim_application.py saves files locally instead of uploading them directly to GCS, adding unnecessary steps.
#Initialize a google cloud client and bucket | ||
self.gcs_client = storage.Client() | ||
self.gcs_bucket_name = gcs_bucket_name | ||
|
||
self.create_bucket_if_not_exists(location) | ||
|
||
def create_bucket_if_not_exists(self, location="US"): | ||
try: | ||
# Check if the bucket already exists | ||
bucket = self.gcs_client.lookup_bucket(self.gcs_bucket_name) | ||
if bucket is None: | ||
print(f"Bucket '{self.gcs_bucket_name}' does not exist. Creating it now...") | ||
# Create the bucket | ||
bucket = self.gcs_client.create_bucket(self.gcs_bucket_name, location=location) | ||
print(f"Bucket '{self.gcs_bucket_name}' created in location '{location}'.") | ||
else: | ||
print(f"Bucket '{self.gcs_bucket_name}' already exists.") | ||
except Exception as e: | ||
print(f"Error creating bucket: {str(e)}") | ||
|
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.
GCS client and bucket creation in abstract_mission.py should not be handled by each mission; this is done globally during initialization.
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.
It seems you are working on the new issue, but you created your branch from an outdated branch. I suggest rebasing your branch onto the latest main branch.
Fixes #123 issue123
This code should allow for creating a bucket/client and uploading to GCS storage using original file path and names.
Removes Local file creation from Save_report method.
imports google cloud storage
created new method called create_bucket_if_not_exists in order to create buckets to store files.
Unable to test due to personal issues. The code should print out a message indicating if the file has been successfully uploaded to the indicated bucket, along with the associated error in case of a failure.