Skip to content
Snippets Groups Projects
Commit fa48de98 authored by des20's avatar des20
Browse files

Issue #58: ADD s3 aws

parent 218b18b4
No related branches found
No related tags found
No related merge requests found
Pipeline #35269 failed
......@@ -59,12 +59,26 @@ class V1::LearningObjects::ChunksController < ApplicationController
params.permit(:id, :file, :_chunkNumber, :_totalChunks, :_chunkFilename, :_chunkIdentifier, :_chunkSize, :_currentChunkSize, :_totalSize, :cancel)
end
# def post_file!
# attachment = @learning_object.attachments.create(name: File.basename(final_file_path), retrieve_link: final_file_path, bundle_name: "TEMP")
# publisher = LearningObjectPublisher.new(DspaceService.create_client)
# publisher.upload @learning_object, final_file_path, attachment
# end
def post_file!
attachment = @learning_object.attachments.create(name: File.basename(final_file_path), retrieve_link: final_file_path, bundle_name: "TEMP")
publisher = LearningObjectPublisher.new(DspaceService.create_client)
publisher.upload @learning_object, final_file_path, attachment
file = open(final_file_path)
data=file.read
s3_client = Aws::S3::Client.new
s3_client.put_object(
key: (@learning_object.id).to_s,
body: data,
bucket: "portalmecs3",
content_type: 'text/plain'
)
end
##
# Move the temporary Sinatra upload to the chunk file location
def save_file!
......@@ -88,7 +102,7 @@ class V1::LearningObjects::ChunksController < ApplicationController
f.write File.read(file_chunk_path)
end
end
FileUtils.chown_R 'portalmec', 'portalmec', final_file_path
# FileUtils.chown_R 'portalmec', 'portalmec', final_file_path
FileUtils.chmod 0644, final_file_path
# Cleanup chunk file directory and all chunk files
FileUtils.rm_rf(chunk_file_directory)
......
......@@ -111,7 +111,6 @@ class UserSerializer < ActiveModel::Serializer
:experience,
:points,
:last_action_at,
:streak,
:high_streak
attribute \
......
......@@ -17,7 +17,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
require 'dspace'
#require 'dspace'
class DspaceService
......
require 'aws-sdk-s3'
require "json"
Aws.config.update(
endpoint: 'https://s3.c3sl.ufpr.br',
access_key_id: ' GMHK6OO49J0FT1ZC5EPT',
secret_access_key: 'MyknbDcne4JRNCi6GJhDsSaH3No4TpdCzIjwcJ0K',
force_path_style: true,
region: 'default',
)
bucket_name = "portalmecs3"
s3_client = Aws::S3::Client.new
file = open("/home/des20/hello.txt")
file_data = file.read
s3_client.put_object(
key: 'hello.txt',
body: file_data,
bucket: bucket_name,
content_type: 'text/plain'
)
object=s3_client.get_object(
key: 'hello.txt',
bucket: 'portalmecs3',
)
puts object.body.read
# wrapper = Aws::S3::Object.new(bucket_name, 'hello.txt')
# obj_data = wrapper.getObjectContent
# puts obj_data
# s3_client.delete_object(
# key: 'hello.txt',
# bucket: 'portalmecs3',
# )
# buckets = s3_client.list_buckets
# puts 'List of S3 buckets:'
# buckets.each do |bucket|
# puts {bucket.name}\t{bucket.creation_date}
# end
\ No newline at end of file
# Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana
#
# This file is part of portalmec.
#
# portalmec is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# portalmec is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with portalmec. If not, see <http://www.gnu.org/licenses/>.
Aws.config.update(
endpoint: 'https://s3.c3sl.ufpr.br',
access_key_id: ' GMHK6OO49J0FT1ZC5EPT',
secret_access_key: 'MyknbDcne4JRNCi6GJhDsSaH3No4TpdCzIjwcJ0K',
force_path_style: true,
region: 'default',
)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment