I'm new to Go. The following code works perfectly in windows, but not on CentOS. I receive a multipart file from the client. The file has the correct size and there are no errors in reading it.
I need to create specific directories for the uploading user and save the files in there. Directories are created just fine, but the file is not written. This whole code runs with no errors on any stage. I'm using Go v1.5.1 and BeeGo framework.
Here's the code:
file , header , err := this.GetFile( "logo" );
defer func(){
err := file.Close()
if err != nil {
fmt.Println( err.Error() )
}
}()
size , seekErr := file.Seek( 0 , 2 )
maxSize , _ := beego.AppConfig.Int64( "MaxSize" )
if err != nil {
response.Data = err.Error()
response.Success = false
} else if seekErr != nil {
response.Data = seekErr.Error()
response.Success = false
} else if size > maxSize {
response.Data = "File too large: " + string(size)
response.Success = false
} else {
if _ , errDE := os.Stat( "static/media/business" ) ; os.IsNotExist( errDE ){
os.Mkdir( "static/media/business" , os.ModeDir )
os.Chmod( "static/media/business" , 0755 )
}
offset , err := file.Seek( 0 , 0 )
if err != nil {
fmt.Println( "Error seeking: " + err.Error() )
}
path := "static/media/business/" + u.( models.User ).Business.BusinessPage
if _ , errDE := os.Stat( path ) ; os.IsNotExist( errDE ){
os.Mkdir( path , os.ModeDir )
os.Chmod( path , 0755 )
}
name := files.GenerateFileName( header.Filename , 24 )
out , err := os.Create( path + "/" + name )
if err != nil {
response.Data = err.Error()
response.Success = false
} else {
defer func(){
err := out.Close()
if err != nil {
fmt.Println( err.Error() )
}
}()
_ , err = io.Copy( out , file )
os.Chmod( path + "/" + name , 0755 )
...
Is there something I'm missing?
UPDATE
It appears that I can io.Copy
to any *.txt file in the mentioned path, but not to an image file. Is that a clue?